Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

initialize_var

Featured Replies

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

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

  • 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 Aviation
My Playland - I69

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

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

  • 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
  • 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 Aviation
My Playland - I69

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.