View Full Version : Globals in Globals
provocating
12-01-2015, 10:13 PM
So this would work in a normal zone folder....
my $var = 1;
sub EVENT_SAY {
quest::say("Var value: " . $var);
}
If I throw this same script in the global folder the script runs fine but the variable value is gone unless of course put it in the same routine. I am sure this has something to do with it actually being a global variable. But in many instances I need that global variable. Ideas?
ghanja
12-02-2015, 12:30 AM
The use of "my" denotes it's not a "global" variable, thus a lexical/local variable.
I'm not sure what you're trying to do exactly bud, but, that said, guessing here, you -may- benefit from plugin::SEV and plugin::REV.
aka $entity->SetEntityVariable("variable_name", "value") and $entity->GetEntityVariable("variable_name")
provocating
12-02-2015, 12:48 AM
I will try the entity variable, thanks.
Kingly_Krab
12-02-2015, 08:13 AM
You could also just use quest globals using the 7 setting for NPC/PC/Zone, so quest::setglobal("Test", 1, 7, "F") would be a quest global for all NPCs, PCs, and zones and could be accessed simply by using $qglobals{"Test"} in any script.
provocating
12-02-2015, 08:35 AM
Overall I am just wondering why the variables quit working when you take an NPC script and throw it in global, that is when it changes.
Kingly_Krab
12-02-2015, 09:12 AM
I mean, as Ghanja mentioned 'my' is the Perl equivalent of Lua's 'local', meaning it's localized to a singular method or file, which could be the issue. It should work correctly being you're initializing it outside of the subroutines as a lexical variable. Due to that, it should also be able to be modified and viewed from inside any subroutine within a given script. Have you attempted removing the 'my' keyword and making it a non-lexical variable and testing it to see if you get any different results?
provocating
12-02-2015, 09:14 AM
That was the first thing I did.
NatedogEZ
12-02-2015, 01:08 PM
This seems to work for me.. what NPC / zone / file is this quest in.
I tried a single NPC and it works fine.. global npc it works fine as well.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.