-
Notifications
You must be signed in to change notification settings - Fork 98
NCalc scripting
Create a new ini
file in NCalcScripts
folder it will automatically loaded at SimHub startup
Script is a ini like file, each section represents an instruction
Exemple of variable déclaration
[Variable]
name='currentgear'
value=[DataCorePlugin.GameData.NewData.Gear]
Each value after the =
is an NCalc expression (https://github.com/SHWotever/ncalc)
Script is executed just before displaying screens and so can access to all the values available
All properties are available to ncalc engine ex : Reading game value exemple :
...
value=[DataCorePlugin.GameData.NewData.Gear]
Reading current script context variable value
...
value=[context.contextvariable]
See NCalc reference https://github.com/ncalc/ncalc/wiki/Operators
See NCalc reference https://github.com/ncalc/ncalc/wiki/Functions
if value
is null, returns replacementvalue
, else returns value
exemple :
...
value=isnull([DataCorePlugin.GameData.NewData.Gear],'N')
if value
is null returns True
else returns False
exemple :
...
value=if(isnull([DataCorePlugin.GameData.NewData.Gear],'No Gear','Gear')
returns formatted value with provided format
exemple :
...
value=format([DataCorePlugin.GameData.NewData.Speed],'0.0')
Returns value as string right aligned with nbchars
characters
Returns alternatively true/false every blinkdelay
(in milliseconds) if currentstatus
is true, else always returns false. blinkername
is used to keep function in sync beetween calls.
exemple :
...
value=blink('rpm',150,[SerialDashPlugin.ComputedRPMPercent]>[SerialDashPlugin.BlinkTriggerRatio])
Returns true after a value change, delay is configured by blinkdelay
(in milliseconds), else always returns false.
exemple :
...
value=if(changed(750,[DataCorePlugin.GameData.NewData.Gear]),'['+[DataCorePlugin.GameData.NewData.Gear]+']', format([DataCorePlugin.GameData.NewData.SpeedKmh],'0'))
Will return the current gear after a gear change otherwise the current speed
Returns true after a value increase, delay is configured by delay
(in milliseconds), else always returns false.
exemple :
...
value=isincreasing(500,round([DataCorePlugin.GameData.NewData.SpeedKmh],0))
Will return true for 500 ms after a raising speed
Returns true after a value decrease, delay is configured by delay
(in milliseconds), else always returns false.
exemple :
...
value=isdecreasing(500,round([DataCorePlugin.GameData.NewData.SpeedKmh],0))
Will return true for 500 ms after a lowering speed
returns a value from 0 to 100, the steps parameter allows to create steps
exemple :
...
value=progress(0,100,[CarSettings_CurrentDisplayedRPMPercent],10)
Replace a text in a string.
exemple :
...
txt=replace(format([PersistantTrackerPlugin.PreviousLap_00],'m\\:ss\\:fff'),'0:00:000','-:--:--')
Returns a time representing the seconds
exemple :
...
txt=secondstotimespan(45454545)
returns : 526.02:15:45
Returns the number of seconds representing the time (Since 5.1.0Beta4)
exemple :
...
txt=timespantoseconds(mytimespan)
returns : 68.0
Description : Creates a new script variable which will available later in the script, it's scope is limited to current script in included scripts
Syntax :
- name : NCalc expression of the variable name to create, they will be after available with
context.
prefix - value : value of the variable
Exemple :
[Variable]
name='currentgear'
value=[DataCorePlugin.GameData.NewData.Gear]
Publish a value in AChub to make it usable in whole program
Syntax :
- name : NCalc expression of the property to export, they will be after available in AChub with
DataCorePlugin.ExternalScript.
prefix - value : NCalc expression of the value of the variable
Exemple :
[ExportProperty]
name='currentgear'
value=[DataCorePlugin.GameData.NewData.Gear]
Export a value usable for led display, value must be numeric
Syntax :
- name : NCalc expression of the property to export, they will be after available in AChub leds mappings with
ExternalScript.
prefix - value : NCalc expression of the value of the variable, must be numeric
Exemple :
[ExportLed]
name='IsInPit'
value=if([DataCorePlugin.GameData.NewData.IsInPit],1,0)
Exports a new event available for events mapping
Syntax :
- name : NCalc expression of the event name to export, they
- trigger : NCalc expression of the trigger (must be boolean), event will only be triggered when value goes from false to true Exemple :
[ExportEvent]
name='GearUP'
trigger=[SerialDashPlugin.ComputedRPMPercent]>[SerialDashPlugin.BlinkTriggerRatio]
Stops script execution Exemple :
[Return]