Achaea EXP Show, not working?

Post Reply
Orlendr
Posts: 71
Joined: Thu May 12, 2011 11:04 pm

Achaea EXP Show, not working?

Post by Orlendr »

function ex_change_echo()
if not tonumber(gmcp.Char.Vitals.nl) == lastXP then
if tonumber(gmcp.Char.Vitals.nl) > lastXP then
echo("\n"..
tonumber(gmcp.Char.Vitals.nl) - lastXP .."experience gained!")
else
echo("\n"..lastXP - tonumber(gmcp.Char.Vitals.nl).."experience lost!")
end
end
end


lastXP = tonumber(gmcp.Char.Vitals.nl)

I have gmcp.Char.Vitals as the event handler, but nothing happens when I gain any experience. can anyone tell me why this isin't working?

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Achaea EXP Show, not working?

Post by Rakon »

First, you'll need to fix the function to accept the proper arguments, second you'll have to make sure everything you want done is actually inside the function call:

Code: Select all

function ex_change_echo(event,args)
 if not tonumber(gmcp.Char.Vitals.nl) == lastXP then
  if tonumber(gmcp.Char.Vitals.nl) > lastXP then
   echo(string.format("\n%i experience gained!", (tonumber(gmcp.Char.Vitals.nl) - lastXP)))
  else
   echo(string.format("\n%i experience lost!",  lastXP))
  end
 end
 lastXP = tonumber(gmcp.Char.Vitals.nl)
end

Let that run, then check the errors dialog in the editor window and see what it says.
Last edited by Rakon on Sun Sep 04, 2011 5:33 pm, edited 1 time in total.

Orlendr
Posts: 71
Joined: Thu May 12, 2011 11:04 pm

Re: Achaea EXP Show, not working?

Post by Orlendr »

This?

object:<event handler function> function:<exp_

Or this?

LUA: ERROR running script exp_change_echo (exp_change_echo) ERROR:

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Achaea EXP Show, not working?

Post by Rakon »

Neither of those are very helpful, actually.
Also, I note that your error starts out with: function <exp_ , where as the function you posted and I edited starts out function ex_ . I would check that you're calling the right function as expected.

I changed my post above, the code section. Try using that.

Orlendr
Posts: 71
Joined: Thu May 12, 2011 11:04 pm

Re: Achaea EXP Show, not working?

Post by Orlendr »

Well, I'm looking at Errors, an Debug, and then stuff that comes up in the prompt...
LUA: ERROR running script prompt detector (Trigger64) ERROR:[string "function Trigger64()..."]:4:
attempt to perform arithmetic on global 'maxHealth' (a nil value)
[ERROR:] object:<event handler function> function:<exp_change_echo>
<>
[ERROR:] object:<prompt detector> function:<Trigger64>
<[string "function Trigger64()..."]:4: attempt to perform arithmetic on global 'maxHealth'
(a nil value)>
System Message:
GMCP event <gmcp.Char> display(gmcp) to see the full content
System Message:
GMCP event <gmcp.Char.Vitals> display(gmcp) to see the full content

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Achaea EXP Show, not working?

Post by Iocun »

Orlendr wrote: if not tonumber(gmcp.Char.Vitals.nl) == lastXP then
This line is the problem. The reason it isn't working is the order the operators are called. "not" has a higher order than "==" and is thus evaluated first. Thus, your line is, spelt out with brackets:

if (not tonumber(gmcp.Char.Vitals.nl)) == lastXP then

The bracket (not tonumber...) will always evaluate as false, since the "not" of a number is false. So your comparison is actually: if false == lastXP then
So your script will only run if lastXP is set to false, which it never is.

What you want instead is:
if not (tonumber(gmcp.char.Vitals.nl) == lastXP) then

Or spelt more shortly:
if tonumber(gmcp.char.Vitals.nl) ~= lastXP then

Use one of those two and it should work.

Orlendr
Posts: 71
Joined: Thu May 12, 2011 11:04 pm

Re: Achaea EXP Show, not working?

Post by Orlendr »

Tried the first, still nothing, should I restart Mudlet first or something? Or try the second one?

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Achaea EXP Show, not working?

Post by Iocun »

Oh one further thing. You need to initialise lastXP for the first time, otherwise it's still nil. So put this on top of the script, before the function:
lastXP = lastXP or tonumber(gmcp.Char.Vitals.nl)

That way, if lastXP is still undefined, it will be set to your current XP.

Orlendr
Posts: 71
Joined: Thu May 12, 2011 11:04 pm

Re: Achaea EXP Show, not working?

Post by Orlendr »

It's giving me an error...

expected to close at line 1 near function

?

Post Reply