The International Simutrans Forum

 

Author Topic: A tool to execute squirrel script  (Read 7166 times)

0 Members and 1 Guest are viewing this topic.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #35 on: June 13, 2020, 08:55:31 AM »
Because it is not finished and largely untested?

Here is a current patch. I need to find more time to work on it: tools work over network now. It still needs more testing for two-click tools, of scripted tools loaded by menuconf.tab, there is no sensible way to mark tiles for action in two-click tools.

Home office, home schooling, and video conferences suck out alot of energy to work on free-time projects like this. Please be patient.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #36 on: June 23, 2020, 07:44:24 PM »
I was thinking, and it occurs to me that it may be an excellent idea to have a "Scenario Tool Windows", so the user would have the possibility to create a tool with options from the graphical interface.  ;D

Edit.
Basically it would be a type of windowed tool, similar to the "Schedule" tool in vehicles / depot.

Something like this improvised interface:  ;)

« Last Edit: June 24, 2020, 03:51:47 AM by Yona-TYT »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #37 on: July 04, 2020, 02:50:04 PM »
Here is a new version of the patch. It should work with network games.

Unpack the zip file into addons/pak128 . Then add a line
Code: [Select]
dialog_tool[34]=,^D
to menuconf.tab to load tools after pressing control+D. Both tools simply remove stuff. The two-click-tool removes stuff in a rectangle given by two mouse clicks.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #38 on: July 04, 2020, 05:06:02 PM »
I am very happy to see progress in this. great!.  <3


Regards!.  ;)

Offline Isaac Eiland-Hall

  • Benevolent Dictator
  • Administrator
  • *
  • Posts: 3921
  • Providing hosting for Simutrans projects
    • pc2.io
  • Languages: EN
Re: A tool to execute squirrel script
« Reply #39 on: July 04, 2020, 06:55:04 PM »
The two-click-tool removes stuff in a rectangle given by two mouse clicks.
Ooh, that's a neat idea!

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: A tool to execute squirrel script
« Reply #40 on: July 05, 2020, 02:34:53 AM »
Thank you for the update! I will look into it in a few days :)

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: A tool to execute squirrel script
« Reply #41 on: July 06, 2020, 01:29:14 PM »
Today I tested the patch briefly in network games and found a problem. The following script makes three slopes and it works in local games. However, in network games, the only first set_slope(pl, p, 82) function was executed, and the rest of set_slope() functions were not executed.

Code: [Select]
function work(pl, pos)
{
local p = pos
command_x.set_slope(pl, p, 82);
p.y -= 1
command_x.set_slope(pl, p, 4);
p.y -= 1
command_x.set_slope(pl, p, 72);
return null
}

This phenomenon occurs on both a client and the server in network games.

EDIT:
simmenu.cc:L907 should be
Code: [Select]
tstrncpy(buf, c, len+1);
to contain '\0' properly.

Even with this fix, I cannot see the icon of scripted tools at the toolbars designated in menuconf.tab. It seems that icon is properly loaded to the scripted tools, and the menubars are properly filled with the scripted tools. I have not made it clear why the icon of scripted tools are invisible.
« Last Edit: July 06, 2020, 03:20:59 PM by THLeaderH »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #42 on: July 06, 2020, 08:02:42 PM »
Thanks for testing! Here is an updated patch.

I could not reproduce your report with network games: It may take some time until the script is properly executed, because each work command is send to server, resend to client, then executed. In the meantime the script is stopped, and it will resume after the work command was executed on the client.

The other problem is fixed. There were multiple problems (menu_arg not properly returned, images initialized in init() instead of constructor, paths were wrong to load addon tools at startup).

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: A tool to execute squirrel script
« Reply #43 on: July 07, 2020, 02:13:19 PM »
I confirmed that the latter problem was fixed. Thank you for the bug fixing!

I found that even print() function output cannot be seen in network games. These phenomena may be only for my environment, so I want to know how it is in others' environment.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #44 on: July 07, 2020, 08:00:18 PM »
print messages are only shown if started with '-debug 2' or higher.

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: A tool to execute squirrel script
« Reply #45 on: August 10, 2020, 05:38:33 AM »
I'm looking forward to the date when the Dwatch's patch is incorporated and I can start writing a scripting tool  :)

Offline Ranran

  • Devotee
  • *
  • Posts: 1548
  • Languages: ja
Re: A tool to execute squirrel script
« Reply #46 on: August 10, 2020, 10:30:39 AM »
I'm looking forward to the date when the Dwatch's patch is incorporated and I can start writing a scripting tool :)
In the meantime, you can make a clarification on the non-working or unfinished code you left on extended.
Their work remains stalled by you not doing it. Because you know the most about it.
when you make a clarification about it we can start processing it. :)

Offline freddyhayward

  • Devotee
  • *
  • Posts: 681
  • Languages: EN
Re: A tool to execute squirrel script
« Reply #47 on: August 10, 2020, 11:48:25 AM »
In the meantime, you can make a clarification on the non-working or unfinished code you left on extended.
Their work remains stalled by you not doing it. Because you know the most about it.
when you make a clarification about it we can start processing it. :)
the scripting code on extended is currently a nuisance, increases compilation times and causes unexpected errors, and serves no purpose at all. Is our goal to bring it in line with standard? If not, it is best to remove it as soon as possible.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #48 on: August 29, 2020, 01:13:29 PM »
This is now submitted in r9187. Sorry for the delay, I definitely needed a break.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #49 on: August 29, 2020, 02:02:21 PM »
Wow, I'm very happy to see this implemented at last! Greetings! .  :p

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10675
  • Languages: De,EN,JP
Re: A tool to execute squirrel script
« Reply #50 on: August 30, 2020, 11:58:41 AM »
Thank you.

Offline Ranran

  • Devotee
  • *
  • Posts: 1548
  • Languages: ja
Re: A tool to execute squirrel script
« Reply #51 on: August 30, 2020, 01:54:48 PM »
the scripting code on extended is currently a nuisance, increases compilation times and causes unexpected errors, and serves no purpose at all. Is our goal to bring it in line with standard? If not, it is best to remove it as soon as possible.
I didn't mean that, I just wanted THLeaderH to address the problem he left behind in Extended. e.g. a meaningless button placed by him on the GUI.

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #52 on: August 31, 2020, 01:46:41 AM »
I've been testing and I have two questions:

1 - Is it possible to call a tool from the toolbar menu? In this case I think that for this the creators of pakset should include a new generic icon for the script tools (it would be very nice).

2 - Can you combine a script tool with a scenario script ?, I mean to be able to pass data from the tool to the scenario script, such as the start and end coordinates from "mark_tiles" for example, with this I can solve a problem in the "Split Regions" script to not use toll gates.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #53 on: August 31, 2020, 06:32:37 AM »
1) yes, write ``scripts(blub)''. It will put all all scripts with ``menu=blub'' into this toolbar. Cursor images can be specified. See the posts of THLeaderH above.

2) start and end coordinates are sent to the scenario with is_work_allowed etc. I do not understand the problem. Please explain in a new thread.

Offline THLeaderH

  • Coder/patcher
  • Devotee
  • *
  • Posts: 424
  • Languages: JP,EN
Re: A tool to execute squirrel script
« Reply #54 on: August 31, 2020, 01:29:21 PM »
Thank you very much for the integration and writing the documents ;D
« Last Edit: August 31, 2020, 02:28:07 PM by THLeaderH »

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #55 on: September 01, 2020, 06:01:20 AM »
@Dwachs
It is possible to make tools that need confirmation for the changes to take effect?.
For example, one click to mark objects then another click to confirm that the objects will be deleted.

Would you show us an example of how to do this? .... Greetings!  8)

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #56 on: September 01, 2020, 07:05:30 AM »
This is not possible currently. One would need to open a script-defined window for this confirmation...

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #57 on: September 01, 2020, 07:54:33 AM »
This is not possible currently. One would need to open a script-defined window for this confirmation...
I mean to confirm by a second click on the map. ;)

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #58 on: September 01, 2020, 10:46:52 AM »
Make a two-click tool, that only does something on the second click. But how do you signal to the tool that you do not want it to execute?

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #59 on: September 02, 2020, 03:43:31 AM »
Make a two-click tool, that only does something on the second click. But how do you signal to the tool that you do not want it to execute?
I've already managed to get something, but it doesn't work quite right I'm afraid.  :-[

This tool allows you to delete all stops in a previously selected city. But for some reason, when there are several types of stops, not all of them are removed.

I leave you attached the tool and a savegame.


Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #60 on: September 02, 2020, 07:40:21 AM »
Maybe remove the halt in a loop until it is not there anymore?

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10675
  • Languages: De,EN,JP
Re: A tool to execute squirrel script
« Reply #61 on: September 02, 2020, 08:22:26 AM »
Not all stops have buil.get_desc().get_type()==34, older paks and e\xtens etc. will have different type. And if there is a city car, the tool remover will remove the citycar. Is there not a call to remove a entire halt? There is an internal routine for doing this.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #62 on: September 02, 2020, 10:33:42 AM »
Not all stops have buil.get_desc().get_type()==34, older paks and e\xtens etc. will have different type.
This should not be the case: those types should be corrected in building-reader.

Yes, might be a good idea to add a routine to remove a stop completely.

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10675
  • Languages: De,EN,JP
Re: A tool to execute squirrel script
« Reply #63 on: September 02, 2020, 01:30:57 PM »
A post office will have type 35 while still being a halt, a dock 11, and a flat dock 36. Thus 34 will not catch all halts.


Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #64 on: September 02, 2020, 01:57:06 PM »
A post office will have type 35 while still being a halt, a dock 11, and a flat dock 36. Thus 34 will not catch all halts.
Certainly I used this in the tutorial scenario to prevent the player from clicking on a stop of another type even if it is connected to the station to be used.  8)


Here is a new version:

- Added a loop when removing stops, this ensures that the stop was removed.
- Now it is checked that the stop belongs to the active player when selecting and eliminating.
- Now it is checked that the stop is "wt_road", since this tool only makes sense for buses or mail trucks.

 
« Last Edit: September 02, 2020, 02:28:45 PM by Yona-TYT »

Offline Yona-TYT

  • Devotee
  • *
  • Posts: 1624
    • Simutrans-BLOG
  • Languages: ES
Re: A tool to execute squirrel script
« Reply #65 on: September 03, 2020, 09:08:38 AM »
I am trying to use an icon to make "mark tile", the problem is that there is only "mark_tiles (pl, start, end)" for tools that require drag and drop.

Can you make this work with one-click tools?


As seen in the image, if I use the "two_click" mode I must drag the cursor by at least one tile.
« Last Edit: September 03, 2020, 09:23:23 AM by Yona-TYT »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #66 on: September 03, 2020, 09:40:30 AM »
I would rather not do this. At the moment, the scripted tools use some auto-cleanup methods do delete those markers, which are not available for one-click tools.

Offline Andarix

  • *
  • Posts: 277
  • Languages: de
Re: A tool to execute squirrel script
« Reply #67 on: December 20, 2020, 11:05:06 AM »
...

Directory Structure
A scripted tool consists of two files, tool.nut and description.tab. tool.nut is required and description.tab is optional, although it is highly recommended. They are put at pakXXX/tool/<script_name>/ . Attached pak128.zip has this directory structure, where script_names are test_tool and test_two_click.

...

Known issues
  • is_valid_pos() cannot return error messages. It can only return state number.
  • Scripted tools cannot be called when simutrans is in network mode. This problem is to be fixed.
....

I have transferred the description to the wiki. Please check the accuracy and correct it if necessary.
« Last Edit: December 20, 2020, 12:09:00 PM by Andarix »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4878
  • Languages: EN, DE, AT
Re: A tool to execute squirrel script
« Reply #68 on: December 20, 2020, 12:57:13 PM »
Looks good. There are now cursor-related settings:
https://forum.simutrans.com/index.php/topic,20577.0.html

Tools should work in network mode. If not, please send a bug report.

Offline Andarix

  • *
  • Posts: 277
  • Languages: de
Re: A tool to execute squirrel script
« Reply #69 on: December 20, 2020, 07:01:33 PM »
I am trying to use an icon to make "mark tile", the problem is that there is only "mark_tiles (pl, start, end)" for tools that require drag and drop.

Can you make this work with one-click tools?


As seen in the image, if I use the "two_click" mode I must drag the cursor by at least one tile.

If a wt_road Halt extensions building has a building, then these are not removed.

And the name and messages should be adapted.