coding help
 
Notifications
Clear all

coding help

24 Posts
2 Users
1 Likes
4,977 Views
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

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


   
Quote
(@romainrob)
Honorable Member
Joined: 4 years ago
Posts: 530
 

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' , '')


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

@romainrob i luvyou guy..... 🤣 


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

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?


   
ReplyQuote
(@romainrob)
Honorable Member
Joined: 4 years ago
Posts: 530
 

NCalc formulas don't allow for variables and storing values.
You'll have to use JS instead:

https://github.com/SHWotever/SimHub/wiki/Javascript-Formula-Engine#storing-data-accross-formula-evaluations

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.

https://github.com/SHWotever/SimHub/wiki/NCalc-scripting


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

@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


   
ReplyQuote
(@romainrob)
Honorable Member
Joined: 4 years ago
Posts: 530
 

Hi,
Idk if I have an example of what you want.
What do you have in mind exactly?


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

I need to have the psi values available at the moment I press esc- back to pit


   
ReplyQuote
(@romainrob)
Honorable Member
Joined: 4 years ago
Posts: 530
 

@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;


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

tx friend, i'll try


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

everything perfect! i can't thank you enough....


   
ReplyQuote
(@romainrob)
Honorable Member
Joined: 4 years ago
Posts: 530
 

@doomsday You're welcome 😉


   
Doomsday reacted
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

@romainrob 

is it possible to switch to next/previous screen via code for a given event?


   
ReplyQuote
(@romainrob)
Honorable Member
Joined: 4 years ago
Posts: 530
 

@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


   
ReplyQuote
(@doomsday)
Trusted Member
Joined: 3 years ago
Posts: 33
Topic starter  

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;

 

This post was modified 2 years ago 2 times by Doomsday

   
ReplyQuote
Page 1 / 2
Share: