Some Macro beginner problems

05/18/2011 16:46 ShadowmanZ#1
I created some functions which should allow to open a file with character names inside to use a whitelist. Within this functions i get some very strange error messages and the bot doesn't do anything.

As you read this seem to be beginner problems. I hope somebody of you is able to help or give a hint ;)

Yellow marked notifications:
Code:
control\macros.txt: ignoring line 'sub getPlayers {' (munch, munch, strange block)
control\macros.txt: ignoring '}' (munch, munch, strange food)
control\macros.txt: ignoring '}' (munch, munch, strange food)
[macro] registering sub addPlayer ...
[macro] registering sub existsInList ...
control\macros.txt: ignoring '$list = getPlayers()' (munch, munch, unknown automacro keyword)
control\macros.txt: ignoring 'if(existsInList("$list",$.lastpm))' (munch, munch, not a pair)
control\macros.txt: ignoring '{' (munch, munch, not a pair)
control\macros.txt: ignoring '}' (munch, munch, strange food)
macros.txt
Code:
sub getPlayers {
	my $player = "";
	my $first = TRUE;
	if(open(FILE, "<:utf8", Settings::getControlFilename("whitelist.txt")))
	{
		while (<FILE>)
		        if (/^\n/) {
				if($first != TRUE) {$player += ", ";}
				$player += $_;
				$first = FALSE;
#				next
			}
		close FILE;
	}
	return $player;
}

sub addPlayer {
	my @lines = ();
	if(open(FILE, "<:utf8", Settings::getControlFilename("whitelist.txt")))
	{
		while (<FILE>)
		{
			s/\x{FEFF}//g; chomp;
		        if (/^\n/) {push @lines,$_;next;}
		}
		close FILE;
	}
	open(FILE, ">:utf8", Settings::getControlFilename("whitelist.txt"));
	print FILE join "\n", @lines;
	close FILE;
}

sub existsInList {
	my ($list, $val) = @_;
	return 0 if ($val eq "");
	my @array = split / *, */, $list;
	$val = lc($val);
	foreach (@array) {
		s/^\s+//;
		s/\s+$//;
		s/\s+/ /g;
		next if $_ eq "";
		return 1 if lc eq $val;
	}
	return 0;
}