Thread: Perl Flags
View Single Post
  #4  
Old 02-06-2004, 11:35 PM
mollymillions's Avatar
mollymillions
Hill Giant
 
Join Date: May 2003
Posts: 176
Default

Regarding the scope of variables, i found that a variable used within a quest is available to that NPC only. Variables declared in plugins or with peval have zone wide scope (cleared when the client zones and I imagine they are all specific to the client, but i hav'nt tested this). The plugin and peval variables are restored once you re-enter that zone, somehow(?). With this knowledge i knocked up a small plugin to handle an associative array to be used for zone-wide flags.

Pugin.pl
Code:
sub get_flag { return $flags{$_[0]}; }
sub set_flag { $flags{$_[0]} = "$_[1]"; }
Use plugin::set_flag("anyname","anyvalue") to set a flag and plugin::get_flag("anyname") to return a flag. The number od flags is limited to the limit for an associative array and the flag names and values can be anything.

Test example:
Code:
sub EVENT_SAY { 
if($text=~/getflag/i){
	$flag = $text;
	$flag =~ s/(getflag)\s(\S+)/$2/;
	$flagvalue=plugin::get_flag("$flag");
	quest::say("$flag = $flagvalue"); }
if($text=~/setflag/i){ 
	$flag = $text;
	$flag =~ s/(setflag )(\S+)\s(\S+)/$2/;
	$flagvalue = $text;
	$flagvalue =~ s/(setflag )(\S+)\s(\S+)/$3/;	
	plugin::set_flag("$flag","$flagvalue"); } 
}
Say "setflag name value" and "getflag name" to test flags with this test example.

Is it possible to declare a variable that will have world -wide and/or client-wide scope?

Also, do the Devs want us users to test the Perl flags as implemented in the code or do the Devs know that- A) it works so dont bother, B) its not implemeted so dont bother, or C) its really low priority so dont bother?
Reply With Quote