Lade...
 

Beiträge zu en_squirrel_script_tools (gegenwärtige Version)

Prozess



Optionen




Version
Version Datum Nutzer
Andarix
Andarix
Andarix
Andarix
Seite anzeigen

Statistiken

Autor Wörter Leerraum Zeichen Druckbare Zeichen
Benutzt Gelöscht Benutzt Gelöscht Benutzt Gelöscht Benutzt Gelöscht
Andarix 754 (100.0%) 0 (0.0%) 512 (100.0%) 0 (0.0%) 6441 (100.0%) 0 (0.0%) 4620 (100.0%) 0 (0.0%)
Gesamt 754 (100.0%) 0 (100.0%) 512 (100.0%) 0 (100.0%) 6441 (100.0%) 0 (100.0%) 4620 (100.0%) 0 (100 %)

Seitenänderungen

Squirrel Script Tool for one or two&nbsp;clicks<a href="#Squirrel_Script_Tool_for_one_or_two_clicks" class="heading-link"><span class="icon icon-link link" ><img src="img/icons/link.png" alt="link"></span></a>


Simutrans 122.0 and higher



I attached the updated patch. Two click tool was supported and some bugs were solved. I attached the code patch file and testing scripts. pak128.zip contains the testing scripts, and test_cursor.zip contains the cursor pak file.



Directory Structure<a href="#Directory_Structure" class="heading-link"><span class="icon icon-link link" ><img src="img/icons/link.png" alt="link"></span></a>




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/&lt;script_name&gt;/ . Attached pak128.zip has this directory structure, where script_names are test_tool and test_two_click.



Please note that script/tool_base.nut at the simutrans executable directory must be placed to make tools work properly. The code patch contains this file tool.



The code below is a sample of description.tab.



description.tab
Copy to clipboard
title=tool for test type=one_click restart=1 menu=my_script icon=one_click_test




  • title: The title of this scripted tool. It is used as the tooltip text.
  • type: It defines the tool type. one_click means one click tool, and two_click means two click tool. The default is one_click.
  • restart: restart=1 means the tool always reloads the script when the tool is exited. If restart=0, the tool vm is not disposed and the state of the tool is preserved until simutrans is terminated.
  • menu: The key to call this tool in menuconf.tab. The value does <a class="wiki" href="i" rel="">i</a>not<a class="wiki" href="/i" rel="">/i</a> have to be unique across scripted tool definitions.
  • icon: It defines the cursor and icon image. For this example, cursor image is image<a class="wiki" href="0" rel="">0</a> of cursor.one_click_test.pak, and icon image is image<a class="wiki" href="1" rel="">1</a> of that pak.


<a href="en_squirrel_script_tools#tiki_top">top</a>



How to call the scripted&nbsp;tools<a href="#How_to_call_the_scripted_tools" class="heading-link"><span class="icon icon-link link" ><img src="img/icons/link.png" alt="link"></span></a>




There are two ways to call scripted tools. The first one is using the script loading window, which is assigned to dialog_tool
<a class="wiki" href="34" rel="">34</a>. When the tool is called with this dialog, the script is always reloaded regardless of "restart" value which is defined in description.tab.



The second way is using toolbars. The toolbar definition in menuconf.tab is required. For example, adding



menuconf.tab
Copy to clipboard
toolbar410=scripts(my_script)




in menuconf.tab shows all scripted tools whose "menu" value is "my_script" at toolbar
<a class="wiki" href="4" rel="">4</a><a class="wiki" href="10" rel="">10</a>. Please note that "icon" value needs to be properly set to show the designated icon of the scripted tools.



<a href="en_squirrel_script_tools#tiki_top">top</a>



Script interfaces for scripted&nbsp;tools<a href="#Script_interfaces_for_scripted_tools" class="heading-link"><span class="icon icon-link link" ><img src="img/icons/link.png" alt="link"></span></a>




When "type" value is one_click, the tool is one click mode and following interfaces are available. The meaning of arguments and return values are same as those of the c++ code.



  • bool init (player_x player)
  • bool exit (player_x player)
  • string work (player_x player, coord3d pos)
  • string check_pos (player_x player, coord3d pos)


When "type" value is two_click, the tool is two click mode and following interfaces are available. The meaning of arguments and return values are same as those of the c++ code.



  • int is_valid_pos (player_x player, coord3d pos, coord3d start)
  • string do_work (player_x player, coord3d start, coord3d end)
  • void mark_tiles (player_x, player, coord3d start, coord3d end)


These functions are called when the scripted tool is launched, exited, clicked, and so on. Implementing any of these functions is optional.



<a href="en_squirrel_script_tools#tiki_top">top</a>



Known issues<a href="#Known_issues" class="heading-link"><span class="icon icon-link link" ><img src="img/icons/link.png" alt="link"></span></a>




  • 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.


<a href="en_squirrel_script_tools#tiki_top">top</a>



Online Benutzer

11 Benutzer (alle) online

Neueste Forenbeiträge