• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Problem with set_named_variable_value

DragonflightDesign

Resource contributor
Messages
1,390
Country
northernireland
When I hit the 'set_named' line, the variable 'landingleft' is definately set to 1. The first bit of strangeness is that xLandingLightsLeft (the XML pointer) was initialised to zero at startup but is now at -1. When I leave the 'set_named' line, xLandingLightsLeft is still at -1.

BOOL FSAPI overhead_landingleft_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags )
{
if (mouse_flags & (FLAGS)MOUSE_LEFTSINGLE)landingleft = 0;
if (mouse_flags & (FLAGS)MOUSE_RIGHTSINGLE)landingleft = 1;
set_named_variable_value (xLandingLightsLeft, (FLOAT64)landingleft);
return FALSE;
}

Later in the icon callback I have this:

FLOAT64 FSAPI overhead_landingleft_icon_cb( PELEMENT_ICON pelement )
{
landingleft = (int)get_named_variable_value (xLandingLightsLeft);
return landingleft;
}

The variable 'landingleft' is set to -1 (the contents of xLandingLightsLeft) instead of the required 1 as set by the mouseclick. I think I can dispose of the obvious first... apart from initialisation, xLandingLightsLeft is absolutely not being touched or set anywhere else.

All of the XML setup and communication is being done in a single gauge. The IDs (e.g. ID xLandingLightLeft) are defined at the top of the gauge. The XML variables are being registered during a PANEL_SERVICE_CONNECT_TO_WINDOW call, so it's definately a one-off setup e.g.

register_named_variable("LandingLightLeft");

The PRE_UPDATE is being used to get the current state of the variables (i.e. looking for a change in the VC) e.g.

xLandingLightsLeft = check_named_variable ("LandingLightsLeft");

Then I also have the opposite effect where updating one XML variable changes three or four others. The two have to be related but...

Any and all ideas welcome, including those poiting to my own stupidiy.
 
Dai,

Unless the error is in the message and not the real code, check this:

register_named_variable("LandingLightLeft");

xLandingLightsLeft = check_named_variable ("LandingLightsLeft");


Names are not quite the same.

Tom
 
I have also found that PANEL_SERVICE_CONNECT_TO_WINDOW is too soon to register L vars. PANEL_SERVICE_PRE_INITIALIZE is a better option. You also don't need to call check_named_variable every PRE_UPDATE to check the ID as L var IDs don't change during the sim session life time. Instead you can dispense with it entirely and do xLandingLightsLeft = register_named_variable("LandingLightsLeft") since register_named_variable returns the same value on creation as check_named_variable does afterwards.
 
Tom - you're right in that it's a typo in the message.

Jon - I'll try that tomorrow when I get another go at the code but it does sound awfully like you're absolutely right.
 
register_named_variable returns the value for the ID... are you storing it in xLandingLightsLeft?
 
No I'm not, Ed - unless this is wrong?

landingleft = (int)get_named_variable_value (xLandingLightsLeft);
 
Last edited:
Jon was right - I was trying to register them too early and was getting crap in the pointers/variables. All working now - thank you all for replying.
 
Back
Top