News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

Default parameter for script-tools

Started by Yona-TYT, November 28, 2024, 06:37:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


I'm planning to create some script tools that will be used in an online game, but there's no way to identify from the scenario which script tool is being used.

For example:
function is_work_allowed_here(pl, tool_id, name, pos, tool)
{
local is_rect = false
foreach(key, value in sender){
if(key == "rect"){
is_rect = true
}
}

if(name == "script_confirm" && is_rect){
forbid_tools_range(sender.rect)
sender.rect = null
return "The rules have been applied correctly."
}

return null
}

0001-Add-default-parameter-for-script-tools.patch

Yona-TYT

Maybe instead of "name" use the "icon" parameter that already exists?.

prissi

Actually, does this matter? The actions of the tool would be still forbidden or allowed based on the rules, or not? Only script tools, that do not affect the game state could not be stopped.

Yona-TYT

Quote from: prissi on December 07, 2024, 12:23:19 AMActually, does this matter? The actions of the tool would be still forbidden or allowed based on the rules, or not? Only script tools, that do not affect the game state could not be stopped.
In fact, this is not to be used with the rules, it is to be used in the function is_work_allowed_here, where it is very useful.

prissi

Why? If a certain tool is forbidden, why you need to forbid a certain script?

Also, what is the meaning of "if player==NULL returns default_param that was used to create the tool" Any tool has its unique default_parameter inhereted from class tool_t, which should not be changed later.

I am sorry, but I still did not understand what you want achieve here.

Yona-TYT

Quote from: prissi on December 07, 2024, 06:11:59 AMWhy? If a certain tool is forbidden, why you need to forbid a certain script?
You see, when there is more than one script tool there is no method that allows us to differentiate one from the other, the default parameter seems perfect to me to know specifically which tool is doing the clicking.


Quote from: prissi on December 07, 2024, 06:11:59 AMAlso, what is the meaning of "if player==NULL returns default_param that was used to create the tool"
Oh no, that was my mistake, please ignore that comment.  :-[



Quote from: prissi on December 07, 2024, 06:11:59 AMAny tool has its unique default_parameter inhereted from class tool_t, which should not be changed later.
But in the case of script tools it is never getting it, not even when the name parameter is specified to the menu bar icon pak file.

prissi

#6
Well, the title can be easily added to the default parameter. But all these entries are translated, i.e. they change with each language.

I have added the folder name as default_parameter in r11448.

Yona-TYT

Quote from: prissi on December 07, 2024, 01:49:49 PMWell, the title can be easily added to the default parameter. But all these entries are translated, i.e. they change with each language.

I have added the folder name as default_parameter in r11448.
Excellent thanks!.

Yona-TYT

Quote from: prissi on December 07, 2024, 01:49:49 PMI have added the folder name as default_parameter in r11448.

Sorry, I hadn't tried this, and it seems that it's not returning the default parameter.

function is_work_allowed_here(pl, tool_id, name, pos, tool)
{

    return name
}

Does the tool have a menu for it to work?.

Edit.
It's strange, in some cases it shows the name, others it shows nothing, and in others it shows buffer dirt.
photo_2024-12-11_20-09-46.jpg


prissi

The default parameter was not static and thus the memory could have been overwritten at this point. Fixed in r11460.

Yona-TYT

I think there is a similar bug in message options.IMG_20241212_072705_319.jpg

prissi

Should not happen, but for safety, I initialised that array with zero. I fixed Englsiche and German on the translator, maybe you can fix spanisch. The last three entries are missing, these are the public chat, company char and private messages.

Andarix

Quote from: prissi on December 12, 2024, 12:56:49 PMShould not happen, but for safety, I initialised that array with zero. I fixed Englsiche and German on the translator, maybe you can fix spanisch. The last three entries are missing, these are the public chat, company char and private messages.

mmh, r11467

Screenshot 2024-12-14 232046.jpg

prissi

Yes, stupid error, must be outside the loop. r11469 should fix this.