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";
}
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
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"];