Problem with elseif trigger

Post Reply
Salvation
Posts: 4
Joined: Mon Aug 23, 2010 7:36 pm

Problem with elseif trigger

Post by Salvation »

New to Mudlet and trying to make a basic melding script. It begins with an alias and continues with a trigger. The idea is to have all the effects after Westwind timed to hit together. My alias (beginmelding) sets the variable demesneeffect to 1 and sends the first effect.

Pattern:
Code: [show] | [select all] lua
^beginmelding
Script:
Code: [show] | [select all] lua
demesneeffect = 1
send( "aerocast westwind demesne")

Since this effect triggers every 10 seconds and is visible to me, I want to use it to time the rest of my meld. The demesneffect is set to 1 by the alias so I don't try to meld when in another Aeromancer's demesne and his Westwind triggers. At the end, it sets the demesneeffect to 0 to prevent repeated casting. Trigger on exact match to the healing line:
A westerly breeze brings in a clean, sweet scent that invigorates your body.

Thunderclouds, the first effect, is cast fine (triggered by the healing line). But after that, nothing else fires. Since Thunderclouds does not fire again, I'm guessing demesneeffect is successfully set to 2. But Eastwind (and so on) is never cast. That's my issue. Thanks for your help.

Script:
Code: [show] | [select all] lua
if demesneeffect == 1 then
	send( "aerocast thunderclouds demesne")
	demesneeffect = 2
elseif demesneffect == 2 then
	send( "aerocast eastwind demesne")
	demesneeffect = 3
elseif demesneffect == 3 then
	send( "aerocast blizzard demesne")
	demesneeffect = 4
elseif demesneffect == 4 then
	send( "aerocast rainbowclouds demesne")
	demesneeffect = 5
elseif demesneffect == 5 then
	send( "aerocast miasma demesne")
	demesneeffect = 6
elseif demesneffect == 6 then
	send( "aerocast twister demesne")
	demesneeffect = 7
elseif demesneffect == 7 then
	send( "aerocast swiftwind demesne")
	demesneeffect = 8
elseif demesneffect == 8 then
	send( "aerocast airnet demesne")
	demesneeffect = 9
elseif demesneffect == 9 then
	send( "aerocast southwind demesne")
	demesneeffect = 10
elseif demesneffect == 10 then
	send( "aerocast illwind demesne")
	demesneeffect = 11
elseif demesneffect == 11 then
	send( "aerocast northwind demesne")
	demesneeffect = 12
elseif demesneffect == 12 then
	send( "aerocast squalls demesne")
	demesneeffect = 0
end

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Problem with elseif trigger

Post by Heiko »


Salvation
Posts: 4
Joined: Mon Aug 23, 2010 7:36 pm

Re: Problem with elseif trigger

Post by Salvation »

I read that and I still don't see what the issue is. Playing around further, the problem definitely seems to be that everything past the first 'elseif' fails to trigger. But I have no idea why.

So, the way it works at the moment (as far as I can tell):
1. beginmelding sets the variable demesneeffect to 1 and casts Westwind.
2. The healing line for Westwind occurs and the trigger fires.
3. The trigger checks that demesneeffect = 1 (from the alias) and casts Thunderclouds. It also sets the variable demesneeffect to 2. I know this because it does not cast Thunderclouds again.
4. The healing line for Westwind occurs again 10s later and since demesneffect = 2, nothing happens. It SHOULD cast Eastwind, but I'm completely lost as to why it does not. :(

The only thing that I'm missing from my trigger that is in the example trigger on the Lua page is the final 'else' statement. But why would that be necessary at all?

Parnakra
Posts: 35
Joined: Tue Apr 21, 2009 10:48 am

Re: Problem with elseif trigger

Post by Parnakra »

It could be that the final else is required, but I can't test this at the moment.

However, as I have an irrational hatred of long elseif-chains, I'd suggest you use something like this:

Initialize table somewhere:
Code: [show] | [select all] lua
spells = {"aerocast thunderclouds demesne","aerocast eastwind demesne","aerocast blizzard demesne","aerocast rainbowclouds demesne","aerocast miasma demesne","aerocast twister demesne","aerocast swiftwind demesne","aerocast airnet demesne","aerocast southwind demesne","aerocast illwind demesne","aerocast northwind demesne","aerocast squalls demesne"}
Alias:
Code: [show] | [select all] lua
currentSpell = 1
send( "aerocast westwind demesne")
Trigger:
Code: [show] | [select all] lua
send(spells[currentSpell])
currentSpell = (currentSpell + 1) % (#spells + 1)
Depending on how that particular skill works (I don't know if the first spell is unique in some way or not), you could put the spell that's sent in the alias in the same table. It also does not check/consider that currentSpell becomes 0 at the end (which isn't an index in this table).

I haven't been able to test this as well, so you might have to tweak the syntax a bit (I've found the # operator sometimes doesn't play well with arithmetic operations).

Salvation
Posts: 4
Joined: Mon Aug 23, 2010 7:36 pm

Re: Problem with elseif trigger

Post by Salvation »

That works perfectly. Thanks! Though I wish I knew why my original trigger wasn't working... hrm.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Problem with elseif trigger

Post by Vadi »

Pankaras solution is great. You can also get away with using the balance queue of m&m for this:
Code: [show] | [select all] lua
spells = {"aerocast thunderclouds demesne","aerocast eastwind demesne","aerocast blizzard demesne","aerocast rainbowclouds demesne","aerocast miasma demesne","aerocast twister demesne","aerocast swiftwind demesne","aerocast airnet demesne","aerocast southwind demesne","aerocast illwind demesne","aerocast northwind demesne","aerocast squalls demesne"}

for i = 1, #spells do
  mm.doadd(spells[i])
end

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

Re: Problem with elseif trigger

Post by demonnic »

The problem was with the variable.
Code: [show] | [select all] lua
if demesneeffect == 1 then
        send( "aerocast thunderclouds demesne")
        demesneeffect = 2
elseif demesneffect == 2 then
you set demesneeffect = 2


and then you check in the rest of the elseif statement for demesneffect ... in the first case, you've mashed the two words together ( demesne..effect) and in the second, you've mashed them together but combined the two "e"s . Took me a minute of looking at it to find it.

Salvation
Posts: 4
Joined: Mon Aug 23, 2010 7:36 pm

Re: Problem with elseif trigger

Post by Salvation »

Ah. Well, thank you! Wish I could've spotted that myself...

Post Reply