News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

A tool to execute squirrel script

Started by THLeaderH, May 05, 2020, 03:49:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#36
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:  ;)


Dwachs

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

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.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

I am very happy to see progress in this. great!.  <3


Regards!.  ;)

Isaac Eiland-Hall

Quote from: Dwachs on July 04, 2020, 02:50:04 PMThe two-click-tool removes stuff in a rectangle given by two mouse clicks.
Ooh, that's a neat idea!

THLeaderH

Thank you for the update! I will look into it in a few days :)

THLeaderH

#41
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.


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

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.

Dwachs

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).
Parsley, sage, rosemary, and maggikraut.

THLeaderH

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.

Dwachs

print messages are only shown if started with '-debug 2' or higher.
Parsley, sage, rosemary, and maggikraut.

THLeaderH

I'm looking forward to the date when the Dwatch's patch is incorporated and I can start writing a scripting tool  :)

Ranran

Quote from: THLeaderH on August 10, 2020, 05:38:33 AMI'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. :)

freddyhayward

Quote from: Ranran on August 10, 2020, 10:30:39 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.

Dwachs

This is now submitted in r9187. Sorry for the delay, I definitely needed a break.
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Wow, I'm very happy to see this implemented at last! Greetings! .  :p

prissi


Ranran

Quote from: freddyhayward on August 10, 2020, 11:48:25 AMthe 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.

Yona-TYT

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.

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

THLeaderH

#54
Thank you very much for the integration and writing the documents ;D

Yona-TYT

@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)

Dwachs

This is not possible currently. One would need to open a script-defined window for this confirmation...
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on September 01, 2020, 07:05:30 AMThis 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. ;)

Dwachs

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?
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Quote from: Dwachs on September 01, 2020, 10:46:52 AMMake 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.


Dwachs

Maybe remove the halt in a loop until it is not there anymore?
Parsley, sage, rosemary, and maggikraut.

prissi

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.

Dwachs

Quote from: prissi 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.
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.
Parsley, sage, rosemary, and maggikraut.

prissi

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.


Yona-TYT

#64
Quote from: prissi on September 02, 2020, 01:30:57 PMA 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.


Yona-TYT

#65
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.

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

Andarix

#67
Quote from: THLeaderH on May 11, 2020, 02:47:04 PM
...

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.

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

Andarix

Quote from: Yona-TYT 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.

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

And the name and messages should be adapted.