Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Elseif Problem

Elseif Problem

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Ahiram   (14 posts)  Bio
Date Sun 24 Apr 2011 01:51 AM (UTC)
Message
<alias
match="^harv$"
enabled="y"
group="General"
regexp="y"
ignore_case="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>if harvestterrain == forest then
Execute ("harvest ginseng;harvest myrrh;harvest lobelia;harvest elm;harvest echinacea;harvest ginger")
elseif harvestterrain == hills then
Execute ("harvest hawthorn;harvest bayberry")
end</send>

This is what I have. Simple and ugly. The problem is that it pays no attention to what the variable actually says and tries to harvest all of it. I deduce that the == is just checking to see whether the variable has a value or is nil, so its going down the list. I'm not sure how to make it stop. I tried putting quotations around forest and hills, but the result of that is that the script doesn't fire at all.

For the sake of completeness, the rest of what I have is posted below.


<triggers>
<trigger
custom_colour="15"
enabled="y"
match="^A ginseng plant \(ginseng\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="15"
enabled="y"
match="^A myrrh bush \(myrrh\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="15"
enabled="y"
match="^A lobelia wildflower \(lobelia\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="15"
enabled="y"
match="^A red elm tree \(elm\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="15"
enabled="y"
match="^A purple coneflower \(echinacea\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="15"
enabled="y"
match="^A wild ginger plant \(ginger\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="15"
enabled="y"
match="^Clusters of nuts \(nuts\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "forest")</send>
</trigger>
<trigger
custom_colour="11"
enabled="y"
match="^A hawthorn plant \(hawthorn\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "hills")</send>
</trigger>
<trigger
custom_colour="11"
enabled="y"
match="^A bayberry tree \(bayberry\)"
regexp="y"
send_to="12"
sequence="100"
><send>SetVariable ("harvestterrain", "hills")</send>
</trigger>
</triggers>
<!-- End Triggers -->
<!-- Variables -->
<variables>
<variable name="harvestterrain">Default</variable>
</variables>
<!-- End Variables -->
<!-- Aliases -->
<aliases>
<alias
match="^checkterrain$"
enabled="y"
group="General"
regexp="y"
ignore_case="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>ColourNote ("white", "green", "Current terrain is @harvestterrain")</send>
</alias>
<alias
match="^harv$"
enabled="y"
group="General"
regexp="y"
ignore_case="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>if harvestterrain == "forest" then
Execute ("harvest ginseng;harvest myrrh;harvest lobelia;harvest elm;harvest echinacea;harvest ginger")
elseif harvestterrain == "hills" then
Execute ("harvest hawthorn;harvest bayberry")
end</send>
</alias>
</aliases>
<!-- End Aliases-->

Sorry for the hideous formatting.
Top

Posted by Fiendish   USA  (2,535 posts)  Bio   Global Moderator
Date Reply #1 on Sun 24 Apr 2011 02:06 AM (UTC)
Message
If you use SetVariable to store the value, then you need to also use GetVariable to recall the value. And yes you need the quotation marks.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #2 on Sun 24 Apr 2011 03:01 AM (UTC)
Message
Beautiful, thank you.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Sun 24 Apr 2011 03:18 AM (UTC)
Message
local terrain = GetVariable("harvestterrain")
if terrain == "forest" then
  -- ...
elseif terrain == "hills" then
  -- ...
end


Also, unless you're doing this to learn (which is awesome), I already wrote this. [1]

[1] http://jonathan.com/achaea/plugins/Harvester.plugin.zip

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #4 on Fri 06 May 2011 10:07 AM (UTC)
Message
Gonna bump this thread because my new problem is similar. And yeah, I want to do as much of this for myself as possible. Learning is tricky, but rewarding in the end.

Hopefully this here is self-explanatory, but just in case, I shall explain what I'm trying to do. I'm trying to make an alias that checks my morph, and if the morph is capable of flipping on reflexes, and reflexes is disabled, then it will flip it on. If its in a morph capable of reflexes, and reflexes is enabled, it will shut it off. If its not in a morph that will allow reflexes, it morphs into one and flips on reflexes. Here's what I have.

<alias
match="^ref$"
enabled="y"
group="Powers"
regexp="y"
ignore_case="y"
expand_variables="y"
send_to="12"
sequence="100">
<send>morph = GetVariable ("morph")
reflexes = GetVariable ("reflexes")
if morph == "icewyrm" then
if reflexes == "off" then
Execute ("reflexes on")
elseif
if morph == "icewyrm" then
if reflexes == "on" then
Execute ("reflexes off")
elseif
Execute ("morph icewyrm;reflexes on")
end</send></alias>

Here's what I get

Compile error
Plugin: Core (called from world: Achaea)
Immediate execution
[string "Alias: "]:7: unexpected symbol near 'if'
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #5 on Fri 06 May 2011 10:17 AM (UTC)
Message
Actually, problems all over this thing. I'm gonna toy with it a moment.
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #6 on Fri 06 May 2011 10:19 AM (UTC)
Message
<alias
match="^ref$"
enabled="y"
group="Powers"
regexp="y"
ignore_case="y"
expand_variables="y"
send_to="12"
sequence="100">
<send>morph = GetVariable ("morph")
reflexes = GetVariable ("reflexes")
if morph == "icewyrm" then
if reflexes == "off" then
Execute ("reflexes on")
elseif
morph == "icewyrm" then
if reflexes == "on" then
Execute ("reflexes off")
else
Execute ("morph icewyrm;reflexes on")
end</send></alias>

I think this is closer to the truth, but still not working.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #7 on Fri 06 May 2011 11:05 AM (UTC)

Amended on Fri 06 May 2011 11:06 AM (UTC) by Twisol

Message
Remember that you can use [code] tags. It makes code a lot easier to look at.
-- Remember to use 'local' within a trigger, unless
-- you're actually trying to set a global variable.
-- Local variables only last the lifetime of the
-- script/scope they're created in, which is usually
-- what you want.
local morph = GetVariable ("morph")
local reflexes = GetVariable ("reflexes")

if morph == "icewyrm" then
  -- Indenting makes code clearer.
  if reflexes == "off" then	    
    Execute ("reflexes on")
  elseif morph == "icewyrm" then
    if reflexes == "on" then
      Execute ("reflexes off")
    else
      Execute ("morph icewyrm;reflexes on")
    end
  -- Aha! You're missing two 'end's.
  -- See why indentation is nice?
  end
end


My comments/changes are in bold.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #8 on Fri 06 May 2011 07:16 PM (UTC)
Message
Thanks again for the help. It almost works. The first two parts are working great, where if you're Icewyrm, you can toggle Reflexes on and off. The last part is not. My assumption is because it checks through the rest of the script, notices that reflexes == "on" or reflexes == "off", and the rest of the script doesn't apply from there. I'm sure adding something like a


elseif
      morph !== "icewyrm" then
      Execute ("morph icewyrm;reflexes on")


would do the trick, but I seem to be blowing the syntax. One more nudge in the right direction? I tried adding another end at the bottom and flipping the !== to !=, but no go.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #9 on Fri 06 May 2011 07:41 PM (UTC)
Message
You have a logic error, too. Look at the nested if-else's:

if morph == "icewyrm" then
  -- morph is icewyrm

  if reflexes == "off" then	    
    Execute ("reflexes on")
  elseif morph == "icewyrm" then
    -- why are we checking this again?
    
    if reflexes == "on" then
      Execute ("reflexes off")
    else
      Execute ("morph icewyrm;reflexes on")
    end
  end
end

My best guess is that you want:
if morph == "icewyrm" then
  if reflexes == "off" then
    Execute ("reflexes on")
  else
    Execute("reflexes off")
else
  if reflexes == "off" then
    Execute ("morph icewyrm;reflexes on")
  end
end

Looks like this can be cleaned up still:
if morph != "icewyrm" then
  Execute ("morph icewyrm")
end

if reflexes == "off" then
  Execute ("reflexes on")
else
  Execute("reflexes off")
end

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #10 on Fri 06 May 2011 08:03 PM (UTC)
Message
I like the second one. Clean, easy to read and understand. However, I'm getting a similar message as before.

Compile error
Plugin: Core (called from world: Achaea)
Immediate execution
[string "Alias: "]:3: 'then' expected near '!' 


Here's the whole thing thus far.

<alias
	match="^ref$"
	enabled="y"
	group="Powers"
	regexp="y"
	ignore_case="y"
	expand_variables="y"
	send_to="12"
	sequence="100">
	<send>local morph = GetVariable ("morph")
		local reflexes = GetVariable ("reflexes")
	    if morph != "icewyrm" then
  		Execute ("morph icewyrm")
		end
		if reflexes == "off" then
  		Execute ("reflexes on")
		else
  		Execute("reflexes off")
		end
	    </send></alias>


Also, I appreciate all the help I've gotten here thus far. Probably would've given up by now if not for the support.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #11 on Fri 06 May 2011 08:06 PM (UTC)

Amended on Fri 06 May 2011 08:07 PM (UTC) by Twisol

Message
Oh, in Lua not-equal is ~=, not !=. Sorry about that.

Also, the indentation seems to be messed up in your script. Not sure if that's just me, but indentation is really, really helpful, I promise!

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Ahiram   (14 posts)  Bio
Date Reply #12 on Fri 06 May 2011 08:11 PM (UTC)
Message
I was just about to post that. :) I'd found the answer in a Lua manual, cleared the whole thing up. Thanks for all the help.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


33,718 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.