Destinationsigns on ChrisTrains (AI) trains with LUA-scripting (part 2)
|
|
Koersborden op de nieuwste ChrisTrains treinen zijn in de scenario editor met de train ID in te stellen zoals te lezen is in de handleiding van de treinen.
Maar met lua scripting is het ook mogelijk om bestemmingen gedurende het scenario aan te passen.
|
Destinationsigns on the latest ChrisTrains trains can be set in the scenario editor by altering the train ID as mentioned in the manual of the trains.
But with LUA scripting it's also possible to change them during the scenario.
|
Voor meer informatie over hoe en wat met LUA scripting verwijs ik je graag naar elders.
Matt Paddlesden heeft een uitstekend filmpje op YouTube en daaruit gemaakte blogs voor degene die zich willen verdiepen in de beginselen van LUA scripting in scenario's.
|
For more information about the basics of LUA scripting I'd like to point you to somewhere else.
Matt Paddlesden has an excelent video on YouTube and created blogs from that for everyone who want to learn the basics of LUA scripting in scenarios.
|
Ik beperkt me hier alleen specifiek op de LUA scripting voor de koersborden.
|
Here I'll confine myself only to LUA scripting for the destinationsigns.
|
Ten tijde van dit schrijven is deze tutorial van toepassing op:
|
When writing this tutorial it applies to:
|
- Stadler Flirt3
- NS VIRMm
- NS SNG
En het zal zeer waarschijnlijk ook van toepassing op toekomstige treinen.
|
And it most likely will also apply to future trains.
|
Om in het scenario een andere bestemming op de koersborden te plaatsen kunnen events worden aangemaakt.
|
Events need to be created to set different destinations on the destinationsigns in a scenario.
|
Het script gebruikt waardes uit twee wagons. De ID van de kopbak (train ID1) en van een tussenbak (train ID2).
|
The script uses values of two carriages. The ID of the lead carriage (train ID1) and of one of the carriages (train ID2).
|
ID's van bestemmingen zijn te vinden in de handleiding van de trein.
|
Destination ID's can be found in the train's manual.
|
Begin het LUA script met het declareren van enkele variabelen:
|
Start the LUA script with the declaration of some variables:
|
Code: Selecteer alles
-- true/false defn
FALSE = 0
TRUE = 1
-- condition return values
CONDITION_NOT_YET_MET = 0
CONDITION_SUCCEEDED = 1
CONDITION_FAILED = 2
Plaats in ieder LUA script voor het eerste event dit:
|
Place this in front of your first event in every LUA script:
|
Maak vervolgens een event aan:
|
Then create an event:
|
Code: Selecteer alles
function OnEvent[EventName]()
newdestination = [destination ID];
destination = SysCall ( "[train ID2]:GetControlValue", "DestinationBoards", 0 );
if (destination < newdestination) then
SysCall ( "[train ID1]:SetControlValue", "DestinationSelector", 0, 1 );
SysCall ( "ScenarioManager:BeginConditionCheck", "[ConditionName]" );
elseif (destination > newdestination) then
SysCall ( "[train ID1]:SetControlValue", "DestinationSelector", 0, -1 );
SysCall ( "ScenarioManager:BeginConditionCheck", "[ConditionName]" );
end
end
Vervolgens wordt er een statuscontrole gestart.
|
Next it starts a condition check.
|
Plaats in ieder LUA script voor de eerste condition dit:
|
Place this in front of your first condition in every LUA script:
|
Code: Selecteer alles
function TestCondition(condition)
_G["TestCondition" .. condition]();
end
Maak vervolgens een condition aan:
|
Then create a condition:
|
Code: Selecteer alles
function TestCondition[ConditionName]()
destination = SysCall ( "[train ID2]:GetControlValue", "DestinationBoards", 0 );
if (destination == newdestination) then
SysCall ( "ScenarioManager:TriggerDeferredEvent", "[EventName2]", 0 );
return CONDITION_SUCCEEDED;
end
return CONDITION_NOT_YET_MET;
end
Maak een tweede event aan om de conditie te stoppen:
|
Create a second event to stop the condition:
|
Code: Selecteer alles
function OnEvent[EventName2]()
SysCall ( "ScenarioManager:EndConditionCheck", "[ConditionName]" );
SysCall ( "[train ID1]:SetControlValue", "DestinationSelector", 0, 0 );
end
Het script leest de huidige bestemming uit en kijkt of de nieuwe bestemming een hogere of lagere ID is.
Vervolgens zul je zien dat op de koersborden oplopen of aflopen tot de gewenste bestemming wordt weergegeven.
|
The script reads the current destination and compares it to the new destination.
When the new ID is higher then destinations will scroll up until the desired destination is reached.
Is the new ID lower then it will scroll down.
|
Roep het event op in de scenario editor om de koersborden van de opgegeven trein te wijzigen naar de opgegeven bestemming.
|
Call the event in the scenario editor to change the destinationsigns of the given train to it's destination.
|
Voorbeelscript:
|
Examplescript:
|
Code: Selecteer alles
-- true/false defn
FALSE = 0
TRUE = 1
-- condition return values
CONDITION_NOT_YET_MET = 0
CONDITION_SUCCEEDED = 1
CONDITION_FAILED = 2
-- Train ID's
TrainA_id1 = 079_12345 -- Flirt front carriage
TrainA_id2 = 67890 -- Flirt carriage
TrainB_id1 = 098_09876 -- SNG front carriage
TrainB_id2 = 54321 -- SNG carriage
-- Destination ID's
BLANCO = 0 -- Blanco
FLIRT_N_I = 1 -- Niet Instappen
FLIRT_WC = 75 -- Wijchen
FLIRT_ZP = 79 -- Zutphen
SNG_N_I = 1 -- Niet Instappen
SNG_UT = 87 -- Utrecht Centraal
SNG_ZL = 98 -- Zwolle
function OnEvent(event)
_G["OnEvent" .. event]();
end
function OnEventDestinationFlirt()
newdestination = FLIRT_WC;
destination = SysCall ( TrainA_id2 .. ":GetControlValue", "DestinationBoards", 0 );
if (destination < newdestination) then
SysCall ( TrainA_id1 .. ":SetControlValue", "DestinationSelector", 0, 1 );
SysCall ( "ScenarioManager:BeginConditionCheck", "DestinationFlirt" );
elseif (destination > newdestination) then
SysCall ( TrainA_id1 .. ":SetControlValue", "DestinationSelector", 0, -1 );
SysCall ( "ScenarioManager:BeginConditionCheck", "DestinationFlirt" );
end
end
function OnEventDestinationSng()
newdestination = SNG_UT;
destination = SysCall ( TrainB_id2 .. ":GetControlValue", "DestinationBoards", 0 );
if (destination < newdestination) then
SysCall ( TrainB_id1 .. ":SetControlValue", "DestinationSelector", 0, 1 );
SysCall ( "ScenarioManager:BeginConditionCheck", "DestinationSng" );
elseif (destination > newdestination) then
SysCall ( TrainB_id1 .. ":SetControlValue", "DestinationSelector", 0, -1 );
SysCall ( "ScenarioManager:BeginConditionCheck", "DestinationSng" );
end
end
function OnEventDestinationFlirtStop()
SysCall ( "ScenarioManager:EndConditionCheck", "DestinationFlirt" );
SysCall ( TrainA_id1 .. ":SetControlValue", "DestinationSelector", 0, 0 );
end
function OnEventDestinationSngStop()
SysCall ( "ScenarioManager:EndConditionCheck", "DestinationSng" );
SysCall ( TrainB_id1 .. ":SetControlValue", "DestinationSelector", 0, 0 );
end
function TestCondition(condition)
_G["TestCondition" .. condition]();
end
function TestConditionDestinationFlirt()
destination = SysCall ( TrainA_id2 .. ":GetControlValue", "DestinationBoards", 0 );
if (destination == newdestination) then
SysCall ( "ScenarioManager:TriggerDeferredEvent", "DestinationFlirtStop", 0 );
return CONDITION_SUCCEEDED;
end
return CONDITION_NOT_YET_MET;
end
function TestConditionDestinationSng()
destination = SysCall ( TrainB_id2 .. ":GetControlValue", "DestinationBoards", 0 );
if (destination == newdestination) then
SysCall ( "ScenarioManager:TriggerDeferredEvent", "DestinationSngStop", 0 );
return CONDITION_SUCCEEDED;
end
return CONDITION_NOT_YET_MET;
end
Wanneer het scenario start zijn de koersborden van de Flirt (TrainA) ingesteld op "Zutphen" en staat op de SNG (TrainB) "Zwolle".
|
The destinationsigns of the Flirt (TrainA) are set to "Zutphen" and on the SNG (TrainB) they'll display "Zwolle" when the scenario starts.
|
Voor beide treinen is er een event die later in het scenario aangeroepen kan worden om een nieuwe bestemming in te stellen.
|
There is a events for both trains that can be called later on in the scenario to set new destinations in the displays.
|
Roep in de editor event "DestinationFlirt" op om de koersborden van de Flirt in te stellen op "Wijchen".
Event "DestinationSng" stelt de SNG in op "Utrecht Centraal".
|
Call event "DestinationFlirt" in the editor to change the destinationsigns of the Flirt to "Wijchen".
Event "DestinationSng" will change the SNG into "Utrecht Centraal".
|