Skip to content

NCalc scripting

Wotever edited this page Apr 30, 2022 · 27 revisions

Script file

Create a new ini file in NCalcScripts folder it will automatically loaded at SimHub startup

Script structure and execution

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

NCalc reference

NCalc variables

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]

NCalc operators

See NCalc reference https://github.com/ncalc/ncalc/wiki/Operators

Embedded NCalc functions

See NCalc reference https://github.com/ncalc/ncalc/wiki/Functions

Additional NCalc functions

isnull(value, replacementvalue)

if value is null, returns replacementvalue, else returns value

exemple :

...
value=isnull([DataCorePlugin.GameData.NewData.Gear],'N')
isnull(value)

if value is null returns True else returns False

exemple :

...
value=if(isnull([DataCorePlugin.GameData.NewData.Gear],'No Gear','Gear')
format(value, format)

returns formatted value with provided format

exemple :

...
value=format([DataCorePlugin.GameData.NewData.Speed],'0.0')
padleft(value, nbchars)

Returns value as string right aligned with nbchars characters

blink(blinkername, blinkdelay, currentstatus)

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])
changed(delay, value)

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

isincreasing(delay, value)

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

isdecreasing(delay, value)

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

progress(startvalue, endvalue, currentvalue, [steps])

returns a value from 0 to 100, the steps parameter allows to create steps

exemple :

...
value=progress(0,100,[CarSettings_CurrentDisplayedRPMPercent],10)
replace(value, search text, replace text)

Replace a text in a string.

exemple :

...
txt=replace(format([PersistantTrackerPlugin.PreviousLap_00],'m\\:ss\\:fff'),'0:00:000','-:--:--')
secondstotimespan(seconds)

Returns a time representing the seconds

exemple :

...
txt=secondstotimespan(45454545)
returns : 526.02:15:45
timespantoseconds(timespan)

Returns the number of seconds representing the time (Since 5.1.0Beta4)

exemple :

...
txt=timespantoseconds(mytimespan)
returns : 68.0

Instructions reference

Creating variable : [Variable]

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]

Exporting property : [ExportProperty]

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]

Exporting led display value : [ExportLed]

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)

Exporting event trigger : [ExportEvent]

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]

Stopping script : [Return]

Stops script execution Exemple :

[Return]

Clone this wiki locally