BRF-commands manual

Example code

This example route is written using csv-type BVE commands. Comments are marked in italic.

#setword{folder,winter} We'll set word "folder" to contain text "winter".

#if{#choice{Do you want summer or winter graphics?}} This makes BRR ask user, which graphics he wants.

#setword{folder,summer} If user clicks left button, word "folder" is set to contain text "summer".

#endif{} #if-structure ends here.

With Structure

.FreeObj(0) myroute\#word{folder}\house.b3d
.FreeObj(1) myroute\#word{folder}\tree.b3d

The command #word is replaced by the contents of word called "folder". "Folder" contains either text "summer" or "winter". BVE searches the house.b3d and tree.b3d from folder "myroute" and from a subfolder that is either "winter" or "summer". This way you can make different subfolders for different sets of graphics, but use one single route file to access them all. No need for different route files for different graphics sets.


#if{#chance{50}}
.Adhesion #rnd{130,160}, .Back(0),
#else{}
.Adhesion #rnd{90,110}, .Back(1), .Fog 128; 128; 128; 0; 1000,
#endif{}

Here's how to do a random weather effect. 50 % chance that weather is good: adhesion is set randomly between 130 and 160. Background image is set to 0, which is supposed to be an image showing clear sky. If it's not good weather, then adhesion is set between 90 and 110, background image is 1 and a fog effect is applied.


#if{#chance{50}}
1000, .RailStart 1; 0,
1025, .Rail 1; 2,
1050, .Rail 1; 4,
1200, .Rail 1; 2,
1225, .RailEnd 1; 0,
#else{}
1000, .RailStart 1; 0, .Turn 0.08,
1025, .Rail 1; -2,
1050, .Rail 1; -4, .Turn -0.08,
1175, .Turn -0.08,
1200, .Rail 1; -2,
1225, .RailEnd 1; 0, .Turn 0.08,
#endif{}

This is the easiest way to do a passing loop, where player's train can either go straight or go through the siding. Each possibility has its own code. There is a better and more flexible way to do this, unless the code is short (like in this case).

Multiple path choices - the smart way to do it

Writing the code for each different path choice and placing them under different #if sections is not a very good solution especially if there are many choices and the code for each choice is long. Every time you want to add e.g. scenery to the multi-pathed section, you must add the code to all the different choices.

The smart way goes as follows

Code & examples

Simple passing loop

/--------------------\
->  ---------------------------------------   ->

Here rail 1 is the straight track and rail 2 is the siding. The rail 2 starts and ends at the points. At the position of the points we can have a code like this:

#setvalue{activerail,#rnd{1,2}}

This will randomize the active rail, the rail the guiding rail follows that is: 1 for the straight track and 2 for the siding. If the train goes straight, there's no need to change anything, so we'll only need to code the siding bit:

(siding start pos),
.RailStart 2...
#setvalue{rail1pos,0}
#setvalue{rail2pos,0}

#if{#equal{#value{activerail},2}}
.Turn (left),
#endif{}

The #setvalue command after the Railstart command is there to set the value of "rail1pos" to zero. The "rail1pos" value is used for storing the relative position of the rail 1. The relative position means the x position compared to the guiding rail. Now that the guiding rail is at the same position with the rail 1, the relative position is 0. The same is for rail 2 (which starts at the position of rail 1 thus rail 0)

At the siding start position we test if the active rail is rail 2, which means the train goes to the siding. If this is the case, we use the rw/csv turn command to turn the guiding rail like normally.

(siding start pos + 25),
#setvalue{rail2pos, -2}

#if{#equal{#value{activerail},2}}
#setvalue{rail1pos,#dv{rail1pos,2}}
#setvalue{rail2pos,#dv{rail2pos,2}}
#endif{}


.Rail 1; #value{rail1pos}...
.Rail 2; #value{rail2pos}...

25m further we set the value "rail2pos" to -2. This is because the rail 2 moves 2m to left during this 25m section to form the actual siding.

Then we again test if the train is taking the siding. In this case we add 2 (metres that is) to the position of both visible rails. This is because the guiding rail doesn't actually move, but we move the both visible rails 2 metres to the right to create the illusion.

After the #if block we'll have to define the position of both the visible rails, note how the x coordinate is read from the values which store the position. If the train is going straight, the value of "rail1pos" is 0, that makes the rail 1 follow the guiding rail 0 (and vice versa) thus the train seems to go straight. The rail 2 is however 2 metres to the left, just like it should!

Instead if the train is taking the siding, the position of rail 1 is 2m to the right and the position of rail 2 is 0m. This makes it look like the guiding rail is following rail 2 now.

(siding start pos + 50),
#setvalue{rail2pos,#dv{rail2pos,-2}}

#if{#equal{#value{activerail},2}}

.Turn (right),
#setvalue{rail1pos,#dv{rail1pos,2}}
#setvalue{rail2pos,#dv{rail2pos,2}}
#endif{}


.Rail 1; #value{rail1pos}...
.Rail 2; #value{rail2pos}...

Another 25m further we subtract another 2m from the position of the rail 2, making it go 2m left again. (The siding is intended to be 4m apart from the main line in this example).

If the train takes the siding, we'll add 2m to the position of both visible rails, and use the rw/csv turn command to make the guiding rail go straight from now on.

Again the relative position of both visible rails are set from the #values "rail1pos" and "rail2pos". If the train goes straight, the "rail1pos" is still 0 and "rail2pos" is -4. If siding, the "rail1pos" is 4 and "rail2pos" is 0.


Now the approach to the siding is finished and you can now use normal BVE route commands to add scenery and stuff to the section between the starting and ending point of the siding, just remember to position all the objects dependant to rail 1 or 2.

The end of the siding is done in much the same way, as well as different path choices. This example probably can't be used straight in more complex systems, but if you got the idea, you should be able to figure out yourself how to do them.

Back to BRF-manual