The International Simutrans Forum

 

Author Topic: "run script" option  (Read 2077 times)

0 Members and 1 Guest are viewing this topic.

Offline ojii

  • *
  • Posts: 149
  • Languages: EN, DE, JA
"run script" option
« on: December 16, 2013, 10:06:52 PM »
Seeing how powerful the scripting interface seems to be (see [1]), I was wondering if it wouldn't make sense to add a way to just run a script (not a scenario) on a game. There would be a menu somewhere to run arbitrary scripts on the current map (eg all .nut files in scripts/ would be listed there or something like that). Could allow for some really cool tools to be built.


[1] http://forum.simutrans.com/index.php?topic=12971.0

Offline isidoro

  • Devotee
  • *
  • Posts: 1129
Re: "run script" option
« Reply #1 on: December 17, 2013, 12:28:16 AM »
Next logical option could be to be able to tie some scripts to interface buttons (pakset or user).


Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4564
  • Languages: EN, DE, AT
Re: "run script" option
« Reply #2 on: December 17, 2013, 07:12:45 AM »
Is certainly possible.

What would you like to do with scripts?

Currently the scripting is limited to retrieve data from the game. Only a few commands are available to alter the game. The main difficulty is that the code to execute commands (building removing etc) does not allow to check whether a command would be successful and the execute it, it rather does both things simultaneously.

(ojii: did you want to link to this thread: http://forum.simutrans.com/index.php?topic=12956.0 ?)

Offline ojii

  • *
  • Posts: 149
  • Languages: EN, DE, JA
Re: "run script" option
« Reply #3 on: December 17, 2013, 08:19:37 AM »
dwachs, yes, my apologise. no idea where my link came from.

in my case, i'm mostly interested in extracting information from games and dumping them to a file. since (as previous discussions showed) it's unlikely that the savegame format will change to something that will be reasonably readable by 3rd party tools (and I understand the reasoning, especially time constraints, for not doing so), a nice work around could be to just write squirrel scripts to export data to some format.

looking through the current api docs I agree that it won't be as useful yet, but looking at the source code it doesn't look like it's that hard for you developers to add more (purely informational) APIs. Something I personally would love to see is something to get all stations and lines (stop_list_x? and line_list_x?).

Modding of games is what got me into programming and I'm always fascinated by the creative things people come up with for games that provide some sort of modability (arguably through paksets simutrans already has a lot covered here) and I would love to see what would happen if simutrans had a reasonably easy way to extend it (even if for now it's just a "read-only" API).

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4564
  • Languages: EN, DE, AT
Re: "run script" option
« Reply #4 on: December 17, 2013, 10:47:10 AM »
looking through the current api docs I agree that it won't be as useful yet, but looking at the source code it doesn't look like it's that hard for you developers to add more (purely informational) APIs. Something I personally would love to see is something to get all stations and lines (stop_list_x? and line_list_x?).
This is an easy addition.

Hard stuff is to make the constructing tools available in the API together with checks that a certain tool can be used at a certain position.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9454
  • Languages: De,EN,JP
Re: "run script" option
« Reply #5 on: December 17, 2013, 10:59:04 AM »
Why is there a need to test. It could just do construction and either get 0 or an error string, just like a real player would get.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4564
  • Languages: EN, DE, AT
Re: "run script" option
« Reply #6 on: December 17, 2013, 12:52:53 PM »
Why is there a need to test. It could just do construction and either get 0 or an error string, just like a real player would get.
If the script wants to do only one single action, then a test is not needed.

If the scripts wants to do a sequence of actions, then a test is needed to ensure that all actions are valid before even spending money on the first action (think of script-controlled AI). Any script-side planning of actions needs some kind of checks whether certain actions are possible.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9454
  • Languages: De,EN,JP
Re: "run script" option
« Reply #7 on: December 17, 2013, 01:29:06 PM »
The non-scripting AI does not do not get any special tests e.g. they transform land for the stations. Then even if way building fails then money is lost.

All testing is done beforehand by the AI. That could be done as well with a script. So in this regards it is not needed to have precognition (which may fail anyway, when just at this moment somebody else builds something.)