TextItem property
 
Notifications
Clear all

TextItem property

3 Posts
2 Users
0 Reactions
2,363 Views
(@lord-frommel)
Active Member
Joined: 4 years ago
Posts: 8
Topic starter  

Hi,

I want to access a TextItem on my panel and set the visibility on or off through java scripting e.g when I press the R on my keyboard, it should be detected and acted upon. Tried the code below. When pressing R I do see the value change from 0 to 1 and back to 0 upon release. Tried several different code all to no avail. Any idea?

TIA

 

var pitRequest = $prop('InputStatus.KeyboardReaderPlugin.R');
if (pitRequest="1")
    {
    Visible=true;
    pitRequest="0";
    }


   
Quote
(@admin5435)
Prominent Member Admin
Joined: 7 years ago
Posts: 732
 

Hi ! You can't access directly to object properties, it's the result (return) of the function which is used,

So instead of visible= you need simply to return the result "return true;" (warning return will make the script exit) 

If you want to keep some state you need to use the root object : https://github.com/SHWotever/SimHub/wiki/Javascript-Formula-Engine#storing-data-accross-formula-evaluations


   
ReplyQuote
(@lord-frommel)
Active Member
Joined: 4 years ago
Posts: 8
Topic starter  

Thanks for your help. Got it working now 😀 

TextItem() will become visible when pit request and invisible once in pit lane:

 

if (root["pitRequest"]==null) { root["pitRequest"]=0; }

if ($prop('InputStatus.KeyboardReaderPlugin.R')) { root["pitRequest"]=1; }

if ($prop('DataCorePlugin.GameRawData.Graphics.IsInPitLane')) { root["pitRequest"]=0; }

return root["pitRequest"]; 

This post was modified 4 years ago 2 times by Lord Frommel

   
ReplyQuote
Share: