Sign in to follow this  

Recommended Posts

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

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

You don't need it anymore. Former FS versions needed it, but that's long ago.

Share this post


Link to post
Share on other sites

>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.

Share this post


Link to post
Share on other sites

You are talking about initialize_var_by_name(), I talked about initialize_var() which are different functions.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Ah well... teach me to scan and not read. ;)

Share this post


Link to post
Share on other sites

>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... ;)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this