Page 1 of 1

Channel Timer

Posted: Sat Sep 03, 2011 9:24 pm
by zephir
Hello, I'm creating a channel timer, that will make the character change to the next channel every 2 hours, and I dont always need to change channel, so I need to activate the code with a keyboard press
the code is the following:

in the profile

Code: Select all

	<onLoad>		
		createTimer();
	</onLoad>

	<onLeaveCombat>	
		activateTimer();
	</onLeaveCombat>
in the user functions

Code: Select all

function changeChannel()
	id = RoMScript("GetCurrentParallelID()");
		if ( id == 1 ) then
			RoMScript("ChangeParallelID(2)");
			printf("Current Channel: 1 \n");
			printf("Changing to Channel: 2 \n");
		elseif ( id == 2 ) then
			RoMScript("ChangeParallelID(3)");
			printf("Current Channel: 2 \n");
			printf("Changing to Channel 3 \n");
		elseif ( id == 3 ) then
			RoMScript("ChangeParallelID(1)");
			printf("Current Channel: 3 \n");
			printf("Changing to Channel 1 \n");
	end;
	yrest(10000);
end;

function activateTimer()
	if( isTriggered("channelTimer") ) then
		removeTimer("channelTimer");
		newTimer("channelTimer");
		startTimer("channelTimer", 7200000);
		printf("Channel Timer loaded \n");	
		changeChannel();				
	end;
end;

function createTimer()
	repeat			
		if( keyPressed( key.VK_F ) ) then
			newTimer("channelTimer");
			startTimer( "channelTimer", 7200000);
			printf("Channel Timer loaded \n");
		end;
	until keyPressed( key.VK_F )
end;
There are somethings that need to be improved, like
detecting if the channel to wich is about to go is available, otherwise it could just end in the same channel
and probably intead of using newTimer, 'startTimer', 'removeTimer'. Just use 'registerTimer'
But the real problem is that the createTimer function, the loops that i've been trying to use like 'repeat' or 'registerTimer' just don't seem to work the way I want, and they stop the code execution with the loop.

Re: Channel Timer

Posted: Sat Sep 03, 2011 10:03 pm
by lisa
well first thing I notice is you get stuck in the loop of createTimer() waiting for the keypress, so it won't do anything else unless you press F.

Second you call for a few functions but I don't see the code for it anywhere.

I don't really understand exactly what you are trying to do, so not sure i can be much more help.

Re: Channel Timer

Posted: Sun Sep 04, 2011 4:33 am
by zephir
yea, chaged some function names before posting but now I think is good.

in onLoad it will create a code that will supposedly run a function if I press a key, and when I press it it will run a timer.

and in onLeaveCombat it will check if the timer is triggered and if it is, it will run the function that will change the channel.