can someone help me to write a code according to this logic:
if condition 1 is true and condition 2 is true and condition 3 =x returns a string
thanks
Hi,
Using NCalc, the if function syntax is:
if(condition,trueResult, falseResult)
So it would look something like:
if(condition1 && condition2 &&Â property== x , 'string' , '')
For example:
if([DataCorePlugin.GameRunning] && [IsInPitLane] && [SpeedKmh]>=60 , 'slow down' , '')
then I ask you two more things:
how can I create a variable to take the value from later?
Can I compute a value from an object? for example from a value displayed in a text object?
NCalc formulas don't allow for variables and storing values.
You'll have to use JS instead:
You can't output a value from a component.
If you need to reuse a computed value, you have to run some formulas outside the dash and output their results to properties.
@romainrob could you give me a practical example for:
calculate a value x in a given moment (ex 6) and resume it from js also when that value is changed
Hi,
Idk if I have an example of what you want.
What do you have in mind exactly?
I need to have the psi values available at the moment I press esc- back to pit
@doomsday I see.
You could use a root variable to store the value across evaluations:
https://github.com/SHWotever/SimHub/wiki/Javascript-Formula-Engine#storing-data-accross-formula-evaluations=
And only update it when you're not in the pit lane.
It would look something like:
if(root.onTrackPressure == null || $prop('IsInPitLane') == 0 ){
root.onTrackPressure = $prop("TyrePressureFrontLeft");
}
return root.onTrackPressure;
tx friend, i'll try
everything perfect! i can't thank you enough....
is it possible to switch to next/previous screen via code for a given event?
@doomsday Hi,
Yes, these actions are available in the "Controls and events" mapper.
In case want a custom event source, you can add one with an NCalc script:
https://github.com/SHWotever/SimHub/wiki/NCalc-scripting#exporting-event-trigger--exportevent
here is the code i made for the tire pressure variable. could you take a look at it? sometimes it works, keeping the value when i press esc, sometimes it doesn't. it remains zero. i made several tests and it seems to happen mostly in multyplayer......... in off line races seem to work....
var tire = $prop('GameRawData.StaticInfo.dryTyresName');
if (tire.indexOf('DHE') != -1){
 delta = 27.8;
}
if (tire.indexOf('DHA') != -1){
 delta = 27.4;
}
if (tire.indexOf('DH-A 275-675_F_315_705_R') != -1){
 delta = 27.4;
}
if (tire.indexOf('DH-A 305/660/315/680') != -1){
 delta = 27.4;
}
if (tire.indexOf('DHD2') != -1){
 delta = 28;
}
var compound = $prop('GameRawData.Graphics.TyreCompound');
if (compound.indexOf('wet_compound') != -1){
 delta = 31.00;
}
if(root.onTrackDeltaPressure == null || $prop('IsInPitLane') == 0 ){
root.onTrackDeltaPressure = ($prop('TyrePressureFrontLeft')-delta);
}
return root.onTrackDeltaPressure;
Â