Hello Reinder,
My layout is working fine with the simulator. But now I start scripting.
The first test using a shuttle script, based on input readings, works fine with the simulator, after some adjustments and syntax trainings by try and test.
Now I want to improve it using a state machine ( a little bit similar to what did EdDie ).
I want to use a fast clock to get 10 seconds tick intervals. I wrote a test script to experiment with :
world.clock.on_tick(function(time)
log.debug(“Type of time :”,class.get(time))
log.debug(time)
end)
log.debug(“Try to set multiplier”)
world.clock.multiplier = 6
log.debug(“Multiplier set to”, world.clock.multiplier)
I expected to have the clock time displayed every 10s. 
All I got was a shutdown of Trainstatic Server a little while after displaying “Try to set multiplier”. 
Can you help me ?
Regards
Serge
Hi Serge,
Good to hear it is working with the simulator.
The clock multiplier can’t be set from the script, it is read only, because the clock is the world clock. You can set the multiplier via the main menu: Objects → Clock.
In the past days I updated the simulator branch with all the master changes. Do you already have that new version? Or is it the older one that gets you the shutdown of Traintastic? (did this script cause the shutdown?, they I can try to reproduce and fix it.)
Beest regards,
Reinder
Hi Reinder,
So I will try to set the multiplier via the clock menu.
I was using the build 1767 from december the 7th when I got the shutdown.
I found your update 1868 in the branch #185. So I have to download your last update and test it.
I‘ll come back to you as soon I have test results.
an hour later ….
I just achived test with the build 1868 :
- Everything is Ok, the ticks from the clock are working just as expected, according to the clock multiplier or the frozen state of the clock, on click event …. including reading the clock multiplier

- then I tried to change the multiplier inside the script. I got the same server shutdown as previously. (see my previous test script description)
It looks like the server shutdown is induced by trying to change the multiplier, even in 1868 build.
So now I will try to improve the “shuttle” script.
Regards
Serge
Hello Reinder,
This morning, using build 1868, I tried to start a LUA script that was working fine with build 1767.
I got troubles with the lines :
local start_sensor = world.get_object("input_9")
log.debug("start_sensor object type :",class.get(start_sensor))
The debug displayed “start_sensor object type : nil”.
Investigating the interface object for inputs, I could not find any. But the input monitor is still working fine and the bloc occupencies are reported OK in the board drawing.
Does that mean that ‘input’ objects have been replaced by “bock.state” and I have change inputs tests by block state tests ?
Regards
Serge
Hi,
The input interface has changed some time ago.
Previously you had to create input objects before you could link them to sensor etc. Now sensors have just a interface/channel/address property and the input object is created under the hood. This is easier for the average user.
You have two options:
- Get an input object using the interface’s
get_input function.
- Map input to sensors/block and use sensor/block events
Hope this gets you further.
Greetings,
Reinder
Hello Reinder,
Going ahead with scripting, I try to write a “security” script. It will be in charge of having the trains to respect the correct behaviour when encountering a signal on block outputs. (running same speed, slowing or stopping according to the signal color). The script is based on block.on_train entered callbacks.
I wrote something that does not work as good as I would like. To improve it, I need to read the real intantaneous speed of a train while accelerating or braking. Is there a throttle property or better a train property or method I canuse ? I didn’t found anything helpfull in the LUA manual.
Regards
Serge
Hi Serge,
That is a nice challenge 
Just had a quick look at the source, the actual speed train.speed isn’t available currently in Lua. speed_max is but that is missing in the (auto generated) documentation, I’ll have a look this evening to correct it.
Greetings,
Reinder
Hi Serge,
I’ve added the Train speed property, the builds are currently running, it will be available in Build #1925 of the master branch and Build #1926 of the simulator branch.
Greetings,
Reinder
Thank you very much Reinder 
.
I saw you added train.speed but also accelerating and braking rates.
It’s amazing how fast you answered.

1 Like