Hi All. Second post here, disclaimer not a programmer. Sorry if topic title is confusing, I'll clarify what I'm trying to do which involves hooking into the GTA5 game engine.
I spawn characters in the game and given them a variable name. For example I would call the first character, Companion1.
Companion1 would be a static variable so as to allow me to interact with that character - animate them, make them talk, etc.
Second/next character spawned would be Companion2, but only if Companion1 is not taken. Similarly, the third character spawned would be Companion3, if 1 and 2 names are not taken.
My problem is how to do I test if CompanionN is available to then use it and increment the next spawn accordingly.
Each time a character is spawned, they are given the name CurrentPed. Each subsequent character is also CurrentPed.
In pseudocode simplified (no else if, no switch):
if (Companion1.Exists() == false) { Companion1 = CurrentPed; } //first spawn, initially called CurrentPed
if (Companion2.Exists() == false) { Companion2 = CurrentPed; } //2nd spawn, initially called CurrentPed
if (Companion3.Exists() == false) { Companion3 = CurrentPed; } //3rd spawn, initially called CurrentPed
Here I'm actually testing if the character exists and it doesn't work. No compiler errors, just run time exception handler error (on a keypress).
So sorry for not TLDRing, but how do I test to see if a variable is already assigned. If it is assigned, I increment, if it isn't assigned I take it.
I spawn characters in the game and given them a variable name. For example I would call the first character, Companion1.
Companion1 would be a static variable so as to allow me to interact with that character - animate them, make them talk, etc.
Second/next character spawned would be Companion2, but only if Companion1 is not taken. Similarly, the third character spawned would be Companion3, if 1 and 2 names are not taken.
My problem is how to do I test if CompanionN is available to then use it and increment the next spawn accordingly.
Each time a character is spawned, they are given the name CurrentPed. Each subsequent character is also CurrentPed.
In pseudocode simplified (no else if, no switch):
if (Companion1.Exists() == false) { Companion1 = CurrentPed; } //first spawn, initially called CurrentPed
if (Companion2.Exists() == false) { Companion2 = CurrentPed; } //2nd spawn, initially called CurrentPed
if (Companion3.Exists() == false) { Companion3 = CurrentPed; } //3rd spawn, initially called CurrentPed
Here I'm actually testing if the character exists and it doesn't work. No compiler errors, just run time exception handler error (on a keypress).
So sorry for not TLDRing, but how do I test to see if a variable is already assigned. If it is assigned, I increment, if it isn't assigned I take it.