User Tools

Site Tools


xmlscripting:xmldb-en

Differences

This shows you the differences between two versions of the page.


xmlscripting:xmldb-en [2023/03/10 15:06] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== General XML Script Examples ======
 +[[:english#objects|{{  :objects.png}}]][[:english|{{  :rocrail-logo-35.png}}]]
 +[[:english|Content]] -> [[:english#objects|Objects]] ->   [[:timed-actions-en|Actions]]
 +  * [[:actions-en|Action Setup]] | [[:actionctrl-en|Action Control]] | [[:actioncond-en|Action Condition]] | **[[:xmlscripting-en|XML Scripting]]** | [[:action-example-en|Example]]
 +    * Examples:
 +      * **[[:xmlscripting:xmldb-en|General]]** | [[:userpages:micha68:virtualfbscript-en|Virtual Sensors]]
 +
 +
 +\\
 +Command Overview: [[http://wiki.rocrail.net/doku.php?id=actions-en#types_commands_parameters|Commands]]
 +\\
 +\\
 +=====Command Examples=====
 +| :!: The quotes on this page can not be used in XML. \\ ToDo: Prefix and suffix the examples with double % chars in the Wiki source. \\ Wrong: <lc id="test"/> \\ Right: %%<lc id="test"/>%% |
 +\\
 +
 +==== Loc Commands====
 +^ Within foreach table loops (no ID is required, its for all that match the conditions) ^ Within if  or as single command outside a loop (ID is required)^ Remarks ^ 
 +| %%<lc cmd="gotoblock"  blockid="Sbf"/>%%                 | <lc id="V200" cmd="gotoblock"  blockid="Sbf"/>          | set the destination block "Sbf" 
 +| <lc cmd="useschedule" scheduleid="Nirvana"/>         | <lc id="V200" cmd="useschedule" scheduleid="Nirvana"/>  | set the schedule to "Nirvana"    | 
 +| <lc cmd="go"/>                                       | <lc id="@loco" cmd="stop"/>                             | Loc start/stop                   
 +| <lc cmd="gotoblock"  blockid="@var6"/>               | <lc id="V200" cmd="gotoblock"  blockid="@var6"/>        | set the destination block to the var6 Text           
 +| <lc cmd="gotoblock"  blockid="$tx1"/>                | <lc id="V200" cmd="gotoblock"  blockid="$tx1"/>         | set the destination block to the tx1 Textfield Text  | 
 +| <lc cmd="useschedule" scheduleid="@var6"/>           | <lc id="V200" cmd="useschedule" scheduleid="@var6"/>      | set the schedule to the var6 Text                  | 
 +| <lc cmd="useschedule" scheduleid="Nirvana"/>         | <lc id="V200" cmd="useschedule" scheduleid="Nirvana"/>  | set the schedule to the tx1 Textfield Text           
 +| <lc cmd="go"/>                                       | <lc id="@var6" cmd="stop"/> or <lc id="$tx1" cmd="stop"/> | Loc @var6 or Loc $tx1 start/stop                   
 +| <lc cmd="velocity" v="5"/>                           | <lc id="V200" cmd="velocity" v="5"/>                    | set the velocity to 5                                | 
 +| -not available- (only one loc can be in a a block)   | <lc id="loco1" cmd="block" blockid="b1"/>               | puts the loc with ID loco1 in Block "b1"             
 +| -not available- (only one loc can be in a a block)   | <lc bkid="bk1" ... /> or <lc bkid="@var6" ... /> or <lc bkid="$tx1" ... />                                     | the lcid of the loc in Block bk1 / @var6 (Variabletext)  /$tx1 (Textfieldtext)     |
 +| <fn fnchanged="3" f3="true"/>                        | <fn id="loco1" fnchanged="3" f3="true"/>                | Functions true/false                                 |
 +
 +Commands: go, stop, velocity, velocity2, percent dispatch, swap, blockside, carcount, min, mid, cruise, max, consist, assigntrain, releasetrain, binstate_on, binstate_off, class, x-go, pomwrite
 +\\
 +\\
 +\\
 +
 +====Variables====
 +^ Within foreach table loops (Sub-ID required, its for all that match the conditions) ^ Within if (ID is required) ^ Remarks ^  
 +| <vr id="var2%oid%" text="empty"/>                    | <vr id="var2" text="empty"/>                    | set the text of a variable                                 |  
 +| <vr id="var2%oid%" value="0"/>                       | <vr id="var2" value="0"/>                       | set the value of a variable                                |  
 +| <vr id="var1%oid%" value="4711" text="empty"/>       | <vr id="var1" value="4711" text="empty"/>       | set value and text of var1                                 |  
 +| <vr id="var3%oid%" value="#var3 + #var5"/>           | <vr id="var3" value="#var3 + #var5"/>           | add the value of var5 to var3                              |  
 +| <vr id="var2%oid%" value="#var2%oid% + 4"/>          | <vr id="var2" value="#var2 + 4"/>               | increase a variable by 4                                   
 +| <vr id="var2%oid%" min="10" max="100" cmd="random"/> | <vr id="var2" min="10" max="100" cmd="random"/> | set the value of var2 to a random between min and max      |  
 +| <vr id="var2%oid%" cmd="start"/>                     | <vr id="var2" cmd="start"/>                     | start the timer of var2 (start/stop)                       |  
 +| <vr id="var3%oid%" text="$tx1"/>                     | <vr id="var3" text="$tx1"/>                     | the text of var3 gets the Text of the Textobject tx1         
 +\\
 +\\
 +\\
 +
 +
 +====Classes====
 +^ Within foreach table loops (no ID is required, its for all that match the conditions) ^ Within if (ID is required) ^ Remarks ^ 
 +| <lc cmd="classset" class="AB,DD"/>                      | <lc id="loco" cmd="classset" class="AB,DD"/>    | set the loc class to AB,DD                                    | 
 +| <lc cmd="classset" class="AB,DD"/>                      | <lc id="@var6" cmd="classset" class="AB,DD"/>   | set the loc class (variable from var6 text) to AB,DD          | 
 +| <bk cmd="classdel" class="AB"/>                         | <bk id="4711" cmd="classdel" class="AB"/>       | deletes the blockclass AB                                     
 +| <bk cmd="classdel" class="AB"/>                         | <bk id="$tx1" cmd="classdel" class="AB"/>       | deletes the blockclass AB  (variable from tx1 Textfield)      | 
 +| <bk cmd="classadd" class="CD,EE1"/>                     | <bk id="4711" cmd="classadd" class="CD,EE1"/>   | adds the blockclass CD,EE1                                    | 
 +\\
 +\\
 +\\
 +====Blocks====
 +^ Within foreach table loops (no ID is required, its for all that match the conditions)  ^ Within if (ID is required) ^ Remarks ^  
 +| -not available- (a block can be reserved only for one loco) | <bk id="b2" cmd="reserve" lcid="loco1"/> | reserve the block b2 for the loco loco1 |
 +\\
 +\\
 +\\
 +
 +====Sensors====
 +^ Within foreach table loops (no ID is required, its for all that match the conditions)  ^ Within if (ID is required) ^ Remarks ^  
 +| -the availability need to clear-  | <fb id="fb1" cmd="on"/> | set the sensor status  |
 +\\
 +\\
 +\\
 +
 +====Textboxes====
 +^ Within foreach table loops (no ID is required, its for all) ^ Within if (ID is required) ^ Remarks ^  
 +| -not availible- (changing a textbox within a loop doesn't make sense)          | <tx id="tx1" format="var1 is #var1 @var1"/>     | updates the text of tx1 with the value and text of var1   
 +\\
 +\\
 +\\
 +
 +
 +====Sleep Command====
 +^ Within foreach table loops (sleep will be done every loop!) ^ Within if (ID is required) ^ Remarks ^  
 +| <sleep time="10"/>                      | <sleep time="10"/>                  | the script is paused by 10 (max. 100ms allowed, values greater than 100ms will be set to 100)     |
 +| <sleep time="#varSleep"/>               | <sleep time="#varSleep"/>           | the script is paused by the value of the variable varSleep (max. 100ms)                           
 +\\
 +\\
 +\\
 +
 +=====Condition Examples=====
 +\\
 +Examples for checking multiple conditions:
 +<code>
 +<if condition="@var1 = hallo|#var1 = 4712">                          : if the text of var1 = hallo AND the value of var1=4712 - if alltrue is not set, it's true         
 +<if condition="@var1 = hallo|#var1 = 4712" alltrue="true">           : if the text of var1 = hallo AND the value of var1=4712     
 +<if condition="@var1 = hallo|#var1 = 4712" alltrue="false">          : if the text of var1 = hallo OR the value of var1=4712 
 +</code>
 +\\
 +Examples for checking conditions, states and classes
 +<code>
 +<if condition="#var1 < &time" state="sg sem3 = green" class="bk 4711 = AB" alltrue="true"> : if var1 < serialtimevalue AND the state of Signal sem3 is green AND the class of Block 4711 is AB
 +</code> 
 +\\
 +\\
 +Example for checking whole tables:
 +<code>
 +<foreach table="lclist" condition="#var2%oid% < &time|#var1 < &time">                      : for each where the variable var2%lcid% < the actual serialtime value AND var1 < the actual serialtime value - if alltrue is not set, it's true         
 +<foreach table="lclist" condition="#var2%oid% < &time|#var1 < &time" alltrue="true">       : for each where the variable var2%lcid% < the actual serialtime value AND var1 < the actual serialtime value    
 +<foreach table="lclist" condition="#var2%oid% < &time|#var1 < &time" alltrue="false">      : for each where the variable var2%lcid% < the actual serialtime value OR var1 < the actual serialtime value     
 +</code>
 +\\
 +\\
 +\\
 +\\
 +
 +=====Sub Scripts and Exit Script=====
 +\\
 +To call a sub-script or to exit the actual script:
 +\\
 +^ XML ^ Remarks ^
 +| <sub file="reset.xml"/>           | start the script reset.xml           
 +| <exit cmt="Raus hier!"/>          | exit this script here        |
 +The cmt=“reason” can be used for tracing. 
 +\\
 +\\
 +\\
 +=====Loop Break=====
 +\\
 +To leave a loop when a condition match:
 +\\
 +^ XML ^ Remarks ^
 +| <break cmt="Its enough." condition="#var1 = 4712"/>       | leaves the loop if the value of var1 = 4712   |  
 +The cmt=“reason” can be used for tracing. 
 +\\
 +\\
 +\\
 +=====Action control===== 
 +\\
 +To call an existing Action if a condition is true
 +\\
 +<code>
 +<actionctrl id="test">
 +    <actioncond id="sw1" subid="" state="straight" type="sw"/>
 +</actionctrl>
 +</code>
 +Action "test" is called, if switch sw1 has the state "straight"\\
 +To call an existing action several times from scripts with several conditions.
 +\\
 +\\
 +\\
 +=====Operator and Car Commands===== 
 +\\
 +<code>
 +<car id="car1" cmd="loaded"/>
 +<actionctrl id="test">
 +    <operator id="op1" cmd="emptycar" carids="DB1"/>
 +</actionctrl>
 +</code>
 +emptycar, loadcar, addcar, leavecar In the carids attribute a list of cars must be specified.
 +\\
 +Car Commands:empty, loaded, maintenance 
 +\\
 +Operator Commands:addcar, removecar, loadcar, emptycar, class 
 +\\
 +\\
 +\\
 +=====System Commands===== 
 +\\
 +<code>
 +<sys cmd="go"/>
 +</code>
 +Commands: stoplocs, stop, go, shutdown, resume, on, off, ebreak, resetfx, time, v0locos, shortcut(short circuit) 
 +\\
 +\\
 +\\
 +
 +=====Example Code===== 
 +\\
 +<code>
 +<xmlscript>
 +  <sys cmd="go"/>
 +  <vr id="var1" value="4712" text="hallo"/>
 +  <tx id="tx1" format="var1 is #var1 @var1"/>
 +  <bk id="b1" cmd="classadd" class="ZZ"/>
 +  <vr id="varX" text="loco1"/>
 +  <lc id="@varX" cmd="classadd" class="ZZ"/>
 +  <car id="car1" cmd="loaded"/>
 +  <actionctrl id="test">
 +    <actioncond id="sw1" subid="" state="straight" type="sw"/>
 +  </actionctrl>
 +  <operator id="op1" cmd="emptycar" carids="DB1"/>
 +  <if condition="@var1 = hallo|#var1 = 4712">
 +    <then>
 +      <tx id="tx1" format="var1 is #var1 @var1 OK!!"/>
 +      <lc id="loco1" cmd="block" blockid="b1"/>
 +      <vr id="var2" min="10" max="100" cmd="random"/>
 +      <tx id="tx1" format="var1 is #var1 @var1 OK!! #var2"/>
 +      <vr id="var2" cmd="start"/>
 +      <vr id="var3" text="$tx1"/>
 +    </then>
 +    <else>
 +      <sub file="reset.xml"/>
 +      <exit cmt="Raus hier!"/>
 +    </else>
 +  </if>
 +  <foreach table="lclist">
 +    <vr id="var4%oid%" value="4711" text="empty"/>
 +    <break cmt="Its enough." condition="#var1 = 4712"/>
 +  </foreach>
 +</xmlscript>
 +
 +</code>
 +
 +
 +