Help with elseif in trigger

Post Reply
MudManMike
Posts: 10
Joined: Tue May 31, 2016 11:46 pm

Help with elseif in trigger

Post by MudManMike »

Hi I am loving Mudlet a lot but will even more once I get more familiar with things I know. I come from a zMUD and cMUD background, but also have a bit of Lua experience.

The MUD I play on has a lot of parties. The party formation lines up in a sort of 3x3 grid. I mainly play a healer and am trying to set up a visual representation of this grid to make healing for parties easier. I have managed to set up a 3x3 grid of geyser gauges that is not perfect but a good starting point.

I can do something like:
Code: [show] | [select all] lua
lua h2bar:setValue(50, 100, "name")
From the command line and see that the gauge works, but I'm having trouble doing this from within the script of the trigger that I have set up to do so.

The trigger is designed to fire of of the following line.
Code: [show] | [select all] lua
| 1.2  name         ldr  688( 688) 1221(1221) 294(303) |  90 |        34214 |
Trigger pattern is:
Code: [show] | [select all] lua
^\|[*\s](\d+\.\d+)\s+((?:\+|.)\w+)\s+(\w+)\s+(|-)(\d+)\(((?:\s|.)\d+)\)\s+(|-)(\d+)\(((?:\s|.)\d+)\)\s+(|-)(\d+)\(((?:\s|.)\d+)\)\s+\|\s+(\d+|\w+)\s+\|\s+(\d+)\s+\|$
Trigger script is:
Code: [show] | [select all] lua
name = matches[3]
hp = matches[6]
maxhp = matches[7]
pos = matches[2]
hpdif = maxhp-hp

echo("\ntrigger fired\n")
-- assign position in formation to one of the 9 formation bars
if toString(matches[2]) == "1.1" then
	h1bar:setValue(toNumber(hp), toNumber(maxhp), toString(name))
	echo("\nif 1 fired\n")
elseif
	matches[2] == "1.2" then
	h2bar:setValue(hp, maxhp, name)
	echo("\nif 2 fired\n")
elseif
	pos == "1.3" then
	h3bar:setValue(hp, maxhp, name)
	echo("\nif 3 fired\n")
elseif
	pos == "2.1" then
	h4bar:setValue(hp, maxhp, name)
elseif
	pos == "2.2" then
	h5bar:setValue(hp, maxhp, name)
elseif
	pos == "2.3" then
	h6bar:setValue(hp, maxhp, name)
elseif
	pos == "3.1" then
	h7bar:setValue(hp, maxhp, name)
elseif
	pos == "3.2" then
	h8bar:setValue(hp, maxhp, name)
elseif
	pos == "3.3" then
	h9bar:setValue(hp, maxhp, name)
end
Ok so I know the trigger works because the trigger fired echo is printed to the screen. I can also echo out the matches[] to see that they are capturing the correct information. Where I am stumped at right now is the if elseif statement test echos won't fire no matter what. I've tried all kinds of things and nothing seems to work. I can't get the gauges to be populated at all.

Is there a kind soul out there that might shed some light onto where I am going wrong?

Thanks,
Mike

MudManMike
Posts: 10
Joined: Tue May 31, 2016 11:46 pm

Re: Help with elseif in trigger

Post by MudManMike »

I don't give up easily. it seems somewhere I saw the toNumber() function used with a capital N so when I was trying to use that to make the string a number it wasn't working right. I ended up figuring out it should be tonumber() all lowercase and now everything seems to work fine. I am sure I will have more questions to post and ask about in the future. I also managed to start a map today and set a room on it manually getting it to work on BatMUD will be one of the next priorities I think.

Have a good day/night and have a drink on me, i'm getting married Saturday
Mike

User avatar
SlySven
Posts: 1023
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Help with elseif in trigger

Post by SlySven »

{I'm not really here right now- on way back from holiday}

Yes, Lua is case sensitive! For functions that I have added (in the C++ code) I use camelCase (all but first word have initial capital) but that has not always been the case for older stuff and other coders - and there are some wrappers in the accompanying Mudlet (and Geyser) Lua files that have the same name but different casing to differentiate between them or from a similarly named "built-in" or standard command (I think echo(...) and Echo(...) fall into this category!)

I wish I had listened to my Mother when I got married - what she said was... well I don't know - I didn't listen, but I wonder if my Ex- did! :lol:

Post Reply