For this tutorial, it is assumed that you will already be aware on how to code basic buttons.
In LFSLapper ("lapper"), you can use Nodes and Zones to ‘trigger’ a sub-routine (a ‘sub’) for something to happen, for instance, open a button to display text.
Node
A Node is an invisible line that cuts across a track, and divides the track into small sections.
Typically, nodes would be used for Start/Finish lines, and splits/sectors. On LFS tracks, these are hard-coded in specific nodes on the track. You can place your own Start, Finish and (up to 3) split/sector lines on your own layouts. If placing these items, LFS and lapper are both configured to give timing details.
If you know the Node number, you can also define that to trigger your own sub.
Zone
A Zone is an invisible circular area that can be placed on any area of the track, or even off-track, and is used to trigger an event.
With LFS running, and LFSLapper connected to your LFS server (either online or local), you can find the Node and Zone coordinates by driving to the area you want to define then typing the following commands;
!node
!zone
Typing !node will display a single number (e.g. 123), and typing !zone will display the X and Y coordinates (e.g. -40 123).
Zone X and Y coordinates can be negative numbers as well as positive. And a zero (0).
These Node and Zone numbers will be needed for any code you make.
Once you have the numbers, you have to Register the node or zone, which is used to define the place chosen.
In lapper, the code could look like;
RegisterNodeAction
The first part of the code defines the Track name abbreviation.
The second part, the number, defines the Node line.
The 3rd part defines the name of the sub(-routine) that is to be run when a car crosses the specified node.
The double quotes can be used if you want a second sub to run when car leaves node. Replace quote marks with name of sub. Leave quote marks if no sub is to be used.
Example sub for node;
This sub basically opens a background box, with RADAR at top, and your speed underneath.
Example output of a Node sub
RegisterZoneAction
The first part of the code defines the Track name abbreviation.
The second part, the 3 numbers, defines the X and Y coordinates, along with the size of the zone in metres. Minimum size would be 1.
The 3rd part defines the name of the sub(-routine) that is to be run when a car crosses into the specified zone.
The double quotes can be used if you want a second sub to run when car leaves zone. Replace quote marks with name of sub. Leave quote marks if no sub is to be used.
Example sub for zone;
Example output of a Zone sub
Or to put it another way, think of SatNav - you put in your destination (the ZONE), and when you get there, you get message that you've arrived (the SUB_ROUTINE).
You can help define the node or zone by adding lines and objects, which will help to show the section better than just seeing an anonymous piece of track or off-track area.
EDIT: Updated for LFSLapper V7.0.4.4 as the sub callback for Zones and Nodes now has an extra variable ($ZoneID).
In LFSLapper ("lapper"), you can use Nodes and Zones to ‘trigger’ a sub-routine (a ‘sub’) for something to happen, for instance, open a button to display text.
Node
A Node is an invisible line that cuts across a track, and divides the track into small sections.
Typically, nodes would be used for Start/Finish lines, and splits/sectors. On LFS tracks, these are hard-coded in specific nodes on the track. You can place your own Start, Finish and (up to 3) split/sector lines on your own layouts. If placing these items, LFS and lapper are both configured to give timing details.
If you know the Node number, you can also define that to trigger your own sub.
Zone
A Zone is an invisible circular area that can be placed on any area of the track, or even off-track, and is used to trigger an event.
With LFS running, and LFSLapper connected to your LFS server (either online or local), you can find the Node and Zone coordinates by driving to the area you want to define then typing the following commands;
!node
!zone
Typing !node will display a single number (e.g. 123), and typing !zone will display the X and Y coordinates (e.g. -40 123).
Zone X and Y coordinates can be negative numbers as well as positive. And a zero (0).
These Node and Zone numbers will be needed for any code you make.
Once you have the numbers, you have to Register the node or zone, which is used to define the place chosen.
In lapper, the code could look like;
RegisterNodeAction ( "AS1", 123, RadarTrap1, "" );
RegisterZoneAction ( "BL1", -40,123, 5 , Ye_Olde_Shoppe, "" );
RegisterNodeAction
The first part of the code defines the Track name abbreviation.
The second part, the number, defines the Node line.
The 3rd part defines the name of the sub(-routine) that is to be run when a car crosses the specified node.
The double quotes can be used if you want a second sub to run when car leaves node. Replace quote marks with name of sub. Leave quote marks if no sub is to be used.
Example sub for node;
Sub RadarTrap1($userName,$ZoneID)
openPrivButton( "ts_back",180,100,20,24,1,-1,16, "");
openPrivButton( "ts_front",181,101,18,22,1,-1,32, "");
openPrivButton( "ts_radartext",180,101,20,8,1,-1,0,"^1R A D A R");
openPrivButton( "ts_speed",102,107,16,5,4,6,0,( langEngine ( "%{ts_speed}%", $TrapText, ToPlayerUnit($TopSpeed), GetCurrentPlayerVar("UnitSpeed") )) );
EndSub
This sub basically opens a background box, with RADAR at top, and your speed underneath.
Example output of a Node sub
RegisterZoneAction
The first part of the code defines the Track name abbreviation.
The second part, the 3 numbers, defines the X and Y coordinates, along with the size of the zone in metres. Minimum size would be 1.
The 3rd part defines the name of the sub(-routine) that is to be run when a car crosses into the specified zone.
The double quotes can be used if you want a second sub to run when car leaves zone. Replace quote marks with name of sub. Leave quote marks if no sub is to be used.
Example sub for zone;
Sub Ye_Olde_Shoppe($userName,$ZoneID)
openPrivButton( "yos_back",80,80,20,24,1,-1,16,"");
openPrivButton( "yos _front",81,81,18,22,1,-1,32,"");
openPrivButton( "yos _text_top",80,81,20,8,1,-1,0,"^1Ye Olde Shoppe");
openPrivButton( "yos _text_main",80,89,6,6,1,-1,0,"^0Welcome to this shop%nl%^0where you find%nl%^0 all sorts of%nl%^0wonderful goods!");
EndSub
Example output of a Zone sub
Or to put it another way, think of SatNav - you put in your destination (the ZONE), and when you get there, you get message that you've arrived (the SUB_ROUTINE).
You can help define the node or zone by adding lines and objects, which will help to show the section better than just seeing an anonymous piece of track or off-track area.
EDIT: Updated for LFSLapper V7.0.4.4 as the sub callback for Zones and Nodes now has an extra variable ($ZoneID).