Page 1 of 1

Display running time

Posted: Mon Apr 11, 2011 3:15 am
by Questionmark
Is there a way to display the bot's running time ingame? I've been trying the following, but I do get an error and I can't seem to fix it.

Code: Select all

<onLeaveCombat>
	addMessage ( "Gevecht #" .. player.Fights );
	if ( player.free_counter1 == 0 ) then
		player.free_counter1 = os.time();
		local uren, minuten, seconden = 0;
	else
		local uur, minuten, seconden = 0;
		seconden = os.difftime(os.time(), player.free_counter1);
		if ( seconden < 60 ) then
			addMessage("Duur: " .. seconden .. "seconden");
		elseif( seconden >= 60 ) then
			min = floor(seconden/60);
			addMessage("Duur: " .. minuten .. " minuten " .. seconden .. "seconden");
		elseif( sec >= 3600 ) then
			min = floor(sec/60);
			uur = floor(min/60);
			addMessage("Duur: " .. uren .. " uren, " .. minuten .. " minuten " .. seconden .. "seconden");
		end;			
	end;
</onLeaveCombat>
The error should be at this line...

Code: Select all

if ( seconden < 60 ) then
and the error is...

Code: Select all

Message: not well-formed (invalid token)
Could someone help me with this?

Re: Display running time

Posted: Mon Apr 11, 2011 3:25 am
by Administrator
Use the CDATA tags to surround the code. Look at the default code provided in some of the events for an example.

Re: Display running time

Posted: Mon Apr 11, 2011 1:12 pm
by JackBlonder
It's because of the

Code: Select all

if ( seconden < 60 ) then
He could also do

Code: Select all

if  60 > seconden ) then
to solve it, right?

Re: Display running time

Posted: Mon Apr 11, 2011 9:20 pm
by rock5
Yes, that's another solution, probably the easiest solution. The third solution that some people use is an escape sequence that I don't know off the top of my head. It's basically a string of 5 or 6 characters that represents the '<' symbol.

Re: Display running time

Posted: Tue Apr 12, 2011 12:49 am
by Questionmark
Using the CDATA tags worked for me.

This is what I got so far and it's working. I haven't been using the bot for over an hour, so I don't know if the part for running more than an hour works, but I think it does.

Code: Select all

<onLeaveCombat><![CDATA[
	if (player.free_counter1 == 0) then
		player.free_counter1 = os.time();
		local tijd = os.difftime(os.time(), player.free_counter1);
		addMessage(player.Fights .. " Gevecht in " .. tijd .. "s");
	else
		local tijd = os.difftime(os.time(), player.free_counter1);
		if (tijd < 60) then
			addMessage(player.Fights .. " Gevechten in " .. tijd .. "s");
		elseif(tijd >= 60) then
			local minuten = math.floor(tijd / 60);
			local seconden = tijd - (minuten * 60);
			addMessage(player.Fights .. " Gevechten in " .. minuten .. "m " .. seconden .. "s");
		elseif(tijd >= 3600) then
			local uren = math.floor(tijd / 3600);
			local minuten = math.floor(tijd / 60) - (uren * 60);
			local seconden = tijd - (minuten * 60);
			addMessage(player.Fights .. " Gevechten in " .. uren .. "u " .. minuten .. "m " ..  seconden .. "s");
		end;         
	end;
]]></onLeaveCombat>
Thanks for the advice.