Set XML Custom Variable value with execute_calculator_code

#1
i have this code which works perfectly when called withing XML interface but it always returns 0 and does not updates the referenced C: variable if called from a gauge callback.

PCSTRINGZ compiled;
UINT32 compilation_size;
FLOAT64 result_f;
SINT32 result_i;
PCSTRINGZ result_s;
gauge_calculator_code_precompile(&compiled,&compilation_size,"111 (>C:Knob1:Value)");
execute_calculator_code(compiled,&result_f,&result_i,&result_s);

Note that if "111 (>C:Knob1:Value)" is replaced with something like "(A:plane heading degrees gyro,degrees)" it works perfectly in gauge callback too.

Does anyones knows how C: variable can be set within gauge callbacks???

*Can anyone explain the ModuleID field of GAUGESLINKAGE/FSLINKAGE struct.
** one more thing reserved4 in the GAUGESHDR is actually the Linkage from which the gauge is derived.
 
Last edited:

n4gix

Resource contributor
#2
You cannot use the function in that manner. For one thing, there's no such thing as a "C:var" in XML. If you want to create/use a custom variable, the correct syntax is "L:var" only.

The symbol "C:" is reserved for calls to a seperate .dll module, such as the fs9gps.dll... C:fs9gps:WaypointICAO

See here for details on using execute_calculator_code:

http://forums.flightsim.com/fswiki/index.php/Code_Sample:_XML_Variables_in_C_Gauges

Note that there are two methods that may be used to obtain the value of a custom L:var in your C gauge:

1.
Code:
// declare the variable and pointer ID for the variable

double pitot_cover = 1 ; // this is the C variable
ID pitot_cover_id; // this is the pointer address to the XML variable

// Register the variable (this is the XML "name," e.g., L:PitotCover)

case PANEL_SERVICE_PRE_INITIALIZE:
    register_named_variable ( "PitotCover" );
break;

// Now you can finally get the float value from the L:variable into your C equivalent

     pitot_cover_id = check_named_variable("PitotCover");
     pitot_cover = get_named_variable_value (pitot_cover_id);
2.
Code:
     FLOAT64 pitot_cover = 0; // first declare the float C variable
     execute_calculator_code("(L:PitotCover,bool)",&pitot_cover,NULL,NULL);
I'll leave it to you to decide which of the two methods is simpler... :)
 
Last edited:
#3
Ok.. let me rephrase the case.

I have made a XML Custom Interface (c++) called Knob1.
I have a gauge also.
Both of the work as they should.

What i want to do is to exchange custom data between these XML interfaces and C/C++ gauges with the use of execute_calculator_code.

When i use execute_calculator_code within the C/C++ gauge it fails to update/retrieve any data related with the C:Knob1 interface. But when execute_calculator_code is called within a XML interface call ( for example called from "SetPropertyValue") it updates/retrieves any data as it should.
 

n4gix

Resource contributor
#4
Okay, that is a different kettle of fish entirely then...

The macro "execute_calculator_code" however AFAIK only works with the FS panel system to read default XML token variables.

I'm sorry, but I don't have an answer for your specific question. :ziplip:
 
Last edited:

taguilo

Resource contributor
#5
<When i use execute_calculator_code within the C/C++ gauge it fails to update/retrieve any data related with the C:Knob1 interface. But when execute_calculator_code is called within a XML interface call ( for example called from "SetPropertyValue") it updates/retrieves any data as it should.>

Hi,

execute_calculator_code("111 (>C:Knob1:YourVar)",NULL,NULL,NULL) should work and you should see the new value AS LONG as you're displaying it in the same gauge as where you are using this function. If you are calling execute_calculator_code in one gauge an reading its value in another, the return will be 0 (because of different instantiantion aspects).
You must use public vars in your DLL to avoid this problem and see the same value across the entire gaugeset.


Tom
 
#6
OK thank's. 
But I believe that something like <Script>(C:x1:v1) (>C:x2:v2)</Script> is still valid within a xml gauge. Isn't it??
 

taguilo

Resource contributor
#7
OK thank's. 
But I believe that something like <Script>(C:x1:v1) (>C:x2:v2)</Script> is still valid within a xml gauge. Isn't it??

Yes, and would be also valid when used within the execute_calculator_code function.

Tom
 
Top