Author Topic: Hot tomake sure txt variable is set before profile is loaded.  (Read 4148 times)

janjan

  • Newbie
  • *
  • Posts: 42
My plugin profile has 4 commands, all relying to txt variables like this:

Code: [Select]
When I say {TXT:HSInQNH} ...
These variables must be defined before the profile is loaded.
I tried to define after the profile had loaded and reset he profile but that did not work as it probably reset those variables as well.

So far I defined them in "VA_Init1" and it was working well for me.

I sent it to others to test and it did not work for all - the text variable was not defined when the profile loaded.
I set my profile to load as default and I guess that since I also have VIACOM plugin, it takes longer for VA to load, enabling my VA_Init1 to complete before my profile loads.
The workaround  was to load another profile and after that load the plugin profile.

I guess that since ..."Note that this function is called asynchronously and there is no guarantee of the order that plugins will be initialized"...

How can I make sure that my VA_Init1 is fully loaded before the profile loads?

My Sequence is this:

Code: [Select]
        public static void VA_Init1(dynamic vaProxy)
        {
....
            AirportsData.TheaterAirfieldData(vaProxy, curTheater);
            RadioCommData.GenCommCmdList(vaProxy);
            SimCommGen.GenSimCmdList(vaProxy);
...
}
The above will also set all text variables for the profile commands e.g.
Code: [Select]
vaProxy.SetText("SimComm", commVar);
And when i load the profile I do this:

Code: [Select]
Begin Boolean Compare : [isJanJanLoaded] Equals False
    ///Reload profile with dynamic commands
    Reset the active profile
End Condition
....







Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Hot tomake sure txt variable is set before profile is loaded.
« Reply #1 on: June 17, 2020, 11:36:21 PM »
As the documentation notes, the order in which plugins are loaded is not guaranteed, however they should load after the profile does, not before (though not necessarily before the "Execute a command each time this profile is loaded" command executes).

Global variables (I.E. variables without a specific prefix to their name) do not get changed or reset when a profile is reloaded.


Instead of having the "Execute a command each time this profile is loaded" command trigger a profile reload immediately, it may be more reliable to either have the command monitor a variable in a loop that is set by your plugin, or to have the plugin trigger a command that triggers the reload instead.

Though, having a plugin set a bunch of variables when it's loaded without regard for the active profile is bad practice.
It'd make more sense to have the "Execute a command each time this profile is loaded" command execute your plugin (I.E. use the "VA_Invoke1" method, rather than the "VA_Init1" method), wait for it to return, and then reload the profile. This way the order of events is more likely to be correct, and you're not loading a bunch or variables into memory that may not be used at all during the session.

janjan

  • Newbie
  • *
  • Posts: 42
Re: Hot tomake sure txt variable is set before profile is loaded.
« Reply #2 on: June 18, 2020, 12:11:00 AM »
When I first started creating this profile I had this problem and you explained that I must define those txt variables before the profile loads, therefore I defined them in the VA_Init1.

I am using "Execute a command each time this profile is loaded" and this command is the one which reset the profile.

What you claim is that I can define those variables in this command e.g. execute a plugin command:
Code: [Select]
Execute external plugin, 'JanJan Plugin for BMS 0.7.3' and wait for return
Set those variables there and the other profile command will be evaluated or loaded into memory only after this command is completed.
So that
Code: [Select]
When I say {TXT:HSInQNH} will be defined.

I tried it and it is working for me but so did the other method.

What then, would you define in VA_Init1 ?

Thanks,


Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Hot tomake sure txt variable is set before profile is loaded.
« Reply #3 on: June 18, 2020, 12:14:23 AM »
What you claim is that I can define those variables in this command e.g. execute a plugin command:
Code: [Select]
Execute external plugin, 'JanJan Plugin for BMS 0.7.3' and wait for return
Set those variables there and the other profile command will be evaluated or loaded into memory only after this
No, I'm saying that if you have the "Execute a command each time this profile is loaded" command trigger your plugin, and then reload the profile, the variables should be initialized correctly.

You'll still need to reload the profile to make this work reliably, that is how the system is intended to be used (though keep in mind variables in profile names is an experimental feature, as has been mentioned to you before).

janjan

  • Newbie
  • *
  • Posts: 42
Re: Hot tomake sure txt variable is set before profile is loaded.
« Reply #4 on: June 18, 2020, 12:23:45 AM »
Thanks,
This is what I changed now.
I added to "Execute a command each time this profile is loaded" execute:
"Execute external plugin, 'JanJan Plugin for BMS 0.7.3' and wait for return" => this one is setting those variables.

I'm aware that this is experimental. I can always plot this in VS and copy to the command line if needed.

What would you set in VA_Init1 then?

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Hot tomake sure txt variable is set before profile is loaded.
« Reply #5 on: June 18, 2020, 12:29:17 AM »
What would you set in VA_Init1 then?

It's up to the plugin author to decide what would be useful, while not needlessly loading things that may not be used by the current profile.

In most cases you'd probably want to use VA_Invoke1 instead, so that when a profile using a specific plugin loads it can initialize its resources on demand.

janjan

  • Newbie
  • *
  • Posts: 42
Re: Hot tomake sure txt variable is set before profile is loaded.
« Reply #6 on: June 18, 2020, 01:08:55 AM »
Thanks!