[Plugin Help] Automatic lockMap Changer

For everything NOT server specific support. Do NOT ask for connectivity help here!.

Moderator: Moderators

catcity
Noob
Noob
Posts: 18
Joined: 20 Oct 2012, 14:31
Noob?: No

[Plugin Help] Automatic lockMap Changer

#1 Post by catcity »

Hi all,

I think it's time for me to ask for help. After figuring it was about time I start trying to get into plugins, rather than keep making my macros.txt even more huge and convoluted than it already is; I decided to start simple and just try and convert one of my macros. In macro terms it couldn't be more simple; it waits a random amount of time between x number and y number and then sets a new random lockMap. Considering it is not doing anything that kore doesn't do in other functions, I thought the building blocks would be there for my to just build from other code in the source, and to a point that is true, except I have no idea what I'm doing.

Here is what I have thrown together so far:

Code: Select all

package autoMapChange;

use Plugins;

Plugins::register("autoMapChange", \&on_unload, \&on_reload);
my $hooks = Plugins::addHooks(
	['mainLoop_pre', \&on_mainLoop]
	);

sub on_unload {
	Plugins::delHooks($hooks);
}

sub on_reload {
	&on_unload;
}
	
sub on_mainLoop {
	if ($config{'autoMapChange'} && time - $KoreStartTime > $config{'autoMapChange'} {
		my @lockMapList = split(/,/, $config{autoMapChange_list});
		my $lockMapNew = $lockMapList[rand @lockMapList];
		my $lockMapPrev = $config{'lockMap'};
		configModify("lockMap", $lockMapNew);
		
		$timeout_ex{'master'}{'time'} = time;
		$KoreStartTime = time + $timeout_ex{'master'}{'timeout'};
		initChangeMap();
	}	
}

sub initChangeMap {
	if ($config{'autoMapChange'}) {
		$changeTime = $config{'autoMapChange_time'} + int(rand $config{'autoMapChange_timeSeed'});
		configModify("autoMapChange", $changeTime, 1);
	}
}

return 1
I can't test it and debug it because it won't run in kore, citing syntax errors near the word 'my' in the line "my $lockMapNew = $lockMapList[rand @lockMapList];" and near the '}' that closes the sub on_mainLoop and sub initChangeMap. I can't figure out what those syntax errors are though. I don't know what I've done wrong.

For a first plugin I'm sure this is wrong in more places than I have noticed right now, but I'm trying to figure it out piece by piece. This syntax error problem has just had me stumped for about two hours however.

Any help is appreciated,

Thanks.
There's two types of people in this world, kid: Those who can, and those who can't; and cats...

[Plugin] Automatic Map Changer
catcity
Noob
Noob
Posts: 18
Joined: 20 Oct 2012, 14:31
Noob?: No

Re: [Plugin Help] Automatic lockMap Changer

#2 Post by catcity »

Typing this before any replies have been validated:

Since I posted this initial question I have got the plugin functional and running. It seems the issue of syntax was fixed by just retyping the whole thing out, word for word. I'm still not sure what the problem was but it at least allowed me to start debugging what was right and wrong about the code.

Now that it's working I'm just putting it through some tests and seeing how I can improve it before I come back to post it.

Cheers.
There's two types of people in this world, kid: Those who can, and those who can't; and cats...

[Plugin] Automatic Map Changer