July 5, 200619 yr In the panel SDK it says:The initialize_ ar function initializes a token variable. Before a token variable can be used, you must initialize it with initialize_var. initialize_var(PMODULE_VAR module_var)Now seems to me that since a module_var is really just a pointer to a structure, that this function would "function" to fill the structure with data.To be honest, I have not used it at all, and everything works. I define the MODULE_VARs I'm using like: MODULE_VAR electricity = { MAIN_BUS_VOLTAGE };in a Globals.cpp, and as EXTERN in an Extern.h, and then when I'm in a callback, I simply use lookup_var(). Now I'm guessing that this fills the structure with the current values and this is why I am fine.So, why would you need this other function? When do you use it?Patrick
July 6, 200619 yr Author Commercial Member >You don't need it anymore. Former FS versions needed it, but>that's long ago.I have to disagree with this statement.initialize_var is used to retrieve a pointer to any variables that are set up as 'broadcast' variables in gauges.Say you define a variable in one gauge and you need to know it's value in another. The first gauge would 'broadcast' the variable by doing this:register_var_by_name(&my_var_name,TYPE_UINT32,"my_var_name");Of course, when the first gauge is closed it must call this to remove the broadcast variable from FS's list:unregister_var_by_name("my_var_name");The second gauge could read that variables value by calling this:initialize_var(&my_var_nameREAD,"my_var_name");my_var_name_READ is defined as:MODULE_VAR my_var_nameREAD;To read the value requires you declare the variable as a pointer reference:PUINT32 my_var_name = (PUINT32)my_var_nameREAD.var_ptr;Then you can read it like this:if (*my_var_name==some_value)So... initialize_var is still used and useful. It's just not needed for anything that's a TOKEN variable as defined in gauges.h. Ed Wilson Mindstar AviationMy Playland - I69
July 6, 200619 yr You are talking about initialize_var_by_name(), I talked about initialize_var() which are different functions.
July 6, 200619 yr Thanks guys.Arne knows I'm doing everything in one multi-gauge. But this is useful to know too, and I appreciate that feedback as well in case I decide to venture into that territory.In fact, it seems like I may wind up doing that evenutally just to not have 3,000 in one gauge. =)Patrick
July 7, 200619 yr Author Commercial Member Ah well... teach me to scan and not read. ;) Ed Wilson Mindstar AviationMy Playland - I69
July 7, 200619 yr Moderator >Then you can read it like this:>>if (*my_var_name==some_value)With regard to reading the 'broadcast variable,' that's pretty dangerous... Better to have some error trapping in place just to be safe:if (shared_var != NULL)then {local_var = *shared_var; }else { /* error trap goes here */ ; }This will ensure that regardless of gauge load order, local_var won't be set until there's valid data in the pointer... ;) Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
July 7, 200619 yr Author Commercial Member True Bill... but your code is horrible... as pennance you must say two "Hail Grace*" and FORTRAN your COBOL. ;)What I do is this:if (my_var_name){ if (*my_var_name==some_value) { }}else{ initialize_var_by_name(&my_var_nameREAD,"my_var_name");}*Grace Hopper, creator of COBOL Ed Wilson Mindstar AviationMy Playland - I69
Create an account or sign in to comment