Thread: qglobals
View Single Post
  #11  
Old 01-25-2009, 03:50 PM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

You were real close. When dealing with globals, I do recommend using defined or !defined to avoid filling the log up with warnings. If you use a standard global == 1 check, and the global doesn't exist in the DB, it'll spam your log with warnings since the variable is undefined. Also, the hash version of globals: $globals{name} is preferred, as the non-hash version: $name==1 is depreciated. It also makes it easier to determine what is a user defined variable and what is a global by looking at the file.

Code:
sub EVENT_SAY {
if($text=~/hail/i && !defined $qglobals{var1}){ //Global is not defined, talk to them.
quest::say("HI 2 u.");
quest::setglobal("var1",1,2,"H25");
}
if($text=~/hail/i && defined $qglobals{var1}){ //Global is defined with a value of 1, don't talk to them.
quest::say("I wont talk to u now!");
 }
}
sub EVENT_SPAWN {
quest::delglobal("var1"); //We want the NPC to be hailed when he pops.
}
A bit off topic, but in case you're wondering, if you need to check a global for a value other than 0 or 1 you'd do a:

Code:
if($text=~/hail/i && defined $qglobals{var1} && $qglobals{var1} == 2){

Last edited by cavedude; 01-25-2009 at 11:56 PM..
Reply With Quote