S-Variables

Hi, all!

This sounds silly (and it is), of course, but...
For the life of me I can't use S-Variables. Something escapes me and I can't get it. It's about the syntax of the messages that must be recorded into the Input Table.

Suppose I want to do this:
1 - Define an S-Variable called "Ouch". 2 - Set it to 1. 3 - Increment it by 7.

Can you give me the EXACT messages ( letter for letter annd word for word ) to be stored into the Input Table and the EXACT way of entering the required Set S-Variable driver commands?
Or do you know about an S-Variable tutorial for nerds?

Sorry about that (and thanks in advance).

PS: I use build 117009.
 
Last edited:
See this page on the Wiki for some help

https://online.ts2009.com/mediaWiki/index.php/Session_Rule_List_with_Parameters#InputTable_Rule


For the Skip If Session-Variable and Wait Until S-Variable driver commands the message must be formatted as:-

svar,svar_name,svar_condition,value - the first entry must be the word svar in lower case,
svar_name is the name of the session variable,
svar_condition is an equality (eg eq for equal, gt for greater than, etc)
value is an integer value to be compared to the session variable.


To increment the value by 7, there has to be a script or asset that performs it. The InputTable itself can't perform the task as it is just a variable container. So if you post what asset your using the table with, maybe we can help more.
 
Hi tfr.stmalmo

This is something that I wrote for someone a few years ago so the kuid numbers may not be the latest versions.

How to use variables in a session.

Variables are a very useful tool for helping to automate many AI actions. They can also help to make sessions more realistic. I have used them to realistically control single line sections of track by using a variable to represent the token that is issued to a driver before he can enter a single line section. They can also be used to keep count of how many wagons are on a particular track in a yard so that they trigger a particular action at the correct time. I've even used them to create an industry at a trackmark. After all the usual industry is only a collection of variables added to an asset. The uses of them are only limited by your imagination.

To use variables you will first have to add the "Input Table" to the session. This is built in to all versions of Trainz. If you want a train to take different actions depending on the value stored in a variable you will also need to add the "Schedule Library" asset as well.

Download the following driver commands from the DLS

"Insert buff label" Kuid:160393:101002

This command puts a label into the schedule to allow the schedule to jump over commands until it finds the label.

"Jump to label" Kuid2:160393:101003:2

This command tells the schedule to jump forward to the label named in the command.

"Set S-Variable" Kuid2:160393:101005:5

Used to set the value in a variable

"Skip if session-variable" Kuid2:160393:101014:3

This command allows the schedule to jump to different labels depending on the value held in a variable.

"Wait Until S-variable V3" Kuid2:160393:101006:3

This command pauses the schedule until a variable meets the condition set in the command.



Set up variables in the Input Table

Variables are declared in the Input Table by typing in svname,xxxxxxxx where xxxxxx is the name of the variable. The comma is important as it is used as a delimiter to indicate to the script where the variable name starts.

They can be manipulated by adding an entry to the Input Table that begins with the word svar followed by a comma - again this is important. Don't put a space after the comma.

svar,set,xxx

Is used to assign a value to the variable xxx e.g. svar,set,3 will set the variable to 3

svar,ran,xxx

Will set the variable to a random number between 1 and the value held in xxx. e.g. svar,ran,5 will generate a random number between 1 and 5.



Comparitors used are

eq means equals e.g. svar,eq,xx
gt means greater than e.g. svar,gt,xx
lt means less than e.g. svar,lt,xx
inc means increment e.g. svar,inc,xx
dec means decrement e.g. svar,dec,xx

Your request for the exact syntax for your variable etc that you need to enter the following into the Input Table

svname,ouch
svar,set,1
svar,inc,7

Make sure that the variable is declared before you try to manipulate it otherwise you will get an error message.

I hope that you find this helpful but if you need further help please post back and I'll try to answer any questions.

Regards

Brian
 
Back
Top