The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Andarix on January 16, 2026, 03:55:52 PM

Title: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Andarix on January 16, 2026, 03:55:52 PM
Quote from: Andarix on January 12, 2026, 04:06:29 PMThe idea is correct, but the value is wrong.

The `tool_id` is correct. Only the object name is passed differently.

The name is passed via the button.
The value 1 is passed via the key "s".

Screenshot 2026-01-12 165907.png


Docu function
is_work_allowed_here() (https://doc.simutrans-germany.com/Simutrans-Squirrel-API/group__quick__return__func.html#ga4e79ca4788f47895ceedbd72d518bd0e)

The description doesn't seem to be entirely correct either. There, "name" is defined as "coord3d".

I think this is a simutrans bug, not a tutorial bug.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: prissi on January 18, 2026, 11:40:35 AM
This is the intended format:
name => object
number => waytype
Only in the later building stages, the object is know, not at the time when the tool is called, since the last waytape is cached with the tool.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Yona-TYT on February 08, 2026, 12:21:35 AM
Quote from: prissi on January 18, 2026, 11:40:35 AMThis is the intended format:
name => object
number => waytype
Only in the later building stages, the object is know, not at the time when the tool is called, since the last waytape is cached with the tool.

To resolve this, I suggest sending the ID of the pressed 'r' key, something like "key_r". This will allow the script to know that the tool is being called from a keyboard shortcut. Then, we need to look in the configuration parameters to see which track/road is assigned to the keyboard shortcut.

Does the pakset handle choosing exactly which road will be called from the keyboard shortcut?.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: prissi on February 08, 2026, 05:38:15 AM
Why? You could just check for the waytype if it is a number string. I.e. waytype==2 and para=="2". If this waytype was allowed before, then it surely will be allowed again, wouldn't it?

You coukd even add a rule like this. It will be always watype=123 and param="123" which forbids using this recall tool.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Andarix on February 08, 2026, 07:22:09 AM
The question is, how many people are using that key during the tutorial? Newcomers, for whom the tutorial is intended, probably aren't.

The issue is that the Squirrel API documentation states that the tool name is passed. Which isn't currently the case.

The fact that we can also consider the waytype via script isn't the problem.

The error therefore doesn't affect Simutrans or the script itself, but rather the Script API. And I'd like to wait for Dwachs's opinion on that.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: prissi on February 09, 2026, 03:19:13 AM
One cannot pass the desc name here. No never, impossible. It will not happen, so one has to change the API documentation that the waytype there is a special desciptor name withich is the number of the waytype. (Alternatively, any illegal name will catch that too.)
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Andarix on February 09, 2026, 03:09:48 PM
I just noticed that the key bindings for routes ignore the timeline.

In pak64.german, the 't' key is assigned to the sand track. However, this track is no longer available at the time of the tutorial.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Yona-TYT on February 09, 2026, 04:53:15 PM
Quote from: Andarix on February 09, 2026, 03:09:48 PMI just noticed that the key bindings for routes ignore the timeline.

In pak64.german, the 't' key is assigned to the sand track. However, this track is no longer available at the time of the tutorial.
It might be a bug in the code that determines whether the track is available (timeline) or not; I was reviewing that very code when creating the patch, I'll try to investigate it.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Yona-TYT on February 10, 2026, 02:47:11 AM
Quote from: Andarix on February 09, 2026, 03:09:48 PMI just noticed that the key bindings for routes ignore the timeline.

In pak64.german, the 't' key is assigned to the sand track. However, this track is no longer available at the time of the tutorial.
I tried using "t" in pak64.german and nothing happens. Did this ever actually work?.

Also, the logic behind this is that it saves the last used track/path; if none has been used, it proceeds to use the most suitable one determined by the timeline.
Title: Re: squirrel script - bug select tool by key function is_work_allowed_here()
Post by: Yona-TYT on February 13, 2026, 12:21:23 PM
I have moved the patch to a separate topic: [Script API] Get last use tool with waytype ID (https://forum.simutrans.com/index.php/topic,23813.msg212102/topicseen.html#msg212102)