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 ➜ Variables not updating?

Variables not updating?

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


Posted by Zerrif   (5 posts)  Bio
Date Tue 20 Dec 2011 06:18 PM (UTC)

Amended on Tue 20 Dec 2011 06:24 PM (UTC) by Zerrif

Message
Hey everyone. Complete newb to MUSH but I'm getting the hang of it pretty fast. I'm running into a small problem, though. From what it looks like, my variables don't update right away.

Here's an example of some output. I tried starting with blank variables, but I got the following error:

[string "Alias: Brewing"]:2: unexpected symbol near '*'

When I input values into the variables beforehand the system runs, but it doesn't update variables properly and ruins my brewing. Getting kind of frustrated now, at the waste of materials I've encountered so far.

For what it's worth, I know what it SHOULD do. If I type brew 1 health, brewamt should equal 5, brewamt2 should equal 10, and brewtype should equal health. I'm aiming to use variables to control these because in the game (Achaea) the multiplicative factors can change based on your skill level, so I figured it would be easier to just change around one number than having to peruse through an entire script and change it all.

Below is my alias so far for what I've got.


<aliases>
  <alias
   name="Brewing"
   match="^brew (\d+) (\D+)$"
   enabled="y"
   echo_alias="y"
   expand_variables="y"
   group="General"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable ("brewamt" , %1 * 5)
SetVariable ("brewamt2" , @brewamt * 2)
SetVariable ("brewtype", "%2")

ColourNote ("white", "black", "@brewamt, @brewamt2, @brewtype")

SetStatus ("@brewamt, @brewamt2, @brewtype")</send>
  </alias>
</aliases>

Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 20 Dec 2011 08:34 PM (UTC)
Message
What happens is that when you send to script, with expand variables checked, it first simply replaces each variable in this text:


SetVariable ("brewamt" , %1 * 5)
SetVariable ("brewamt2" , @brewamt * 2)
SetVariable ("brewtype", "%2")

ColourNote ("white", "black", "@brewamt, @brewamt2, @brewtype")

SetStatus ("@brewamt, @brewamt2, @brewtype")


... with the variable contents. So for example, if (before it executes) brewamt is "10", brewamt2 is "20", and brewtype is "health" then you will get:


SetVariable ("brewamt" , %1 * 5)
SetVariable ("brewamt2" , 10 * 2)
SetVariable ("brewtype", "%2")

ColourNote ("white", "black", "10, 20, health")

SetStatus ("10, 20, health")


That's before it gets your wildcards. It is before the script executes. Then the script executes. It's too late to use the variables you set inside the script like that.

The simple fix is to keep using the wildcards, eg.



SetVariable ("brewamt" , %1 * 5)
SetVariable ("brewamt2" , @brewamt * 2)
SetVariable ("brewtype", "%2")

ColourNote ("white", "black", %1 * 5 .. ", " .. %1 * 10 .. ", " .. %2)

SetStatus (%1 * 5 .. ", " .. %1 * 10 .. ", " .. %2)


Are you using these variables anywhere else? If not, there is no real point in setting them. Also you can use GetVariable, because this works:


SetVariable ("brewtype" , "%2")
ColourNote ("white", "black", "Brew type now: " .. GetVariable ("brewtype"))


That works because GetVariable executes as part of the script, and gets back the variable you just set.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zerrif   (5 posts)  Bio
Date Reply #2 on Tue 20 Dec 2011 09:49 PM (UTC)
Message
Ah that's it! Thanks!

I guess I'm not really using the variables anywhere else in other aliases, but the thing is that this script was all just a check for me before I do the whole entire thing.

In Achaea, you have to get 4 different reagents from your rift before you put them in a pot to boil, so I wanted to save time by not having to go through each potential mix and change the math around (depending on skill level you either need 4, or 5 of a reagant for a fill, and some recipes call for doubles of certain items meaning 8 or 10 for one fill). You know, trying to be an efficient coder! :P

If I can get the entire thing to work, I'll be sure to post a full alias for further use and tweaking by other users.

Thanks again! Off to code!
Top

Posted by Zerrif   (5 posts)  Bio
Date Reply #3 on Tue 20 Dec 2011 11:17 PM (UTC)

Amended on Tue 20 Dec 2011 11:18 PM (UTC) by Zerrif

Message
Here's the updated code, and it's working? It's really basic right now, and really cluttered-- but you'll see why I wanted variables. Imagine having to change all those amounts one by one when you get to the point where you change the multiplier!

Oh, @pot is also a variable I defined outside of this: basically pots in Achaea come with their own ID, and you always want to make sure you drop and boil the same pot you put stuff in. So I just saved my ID as the variable @pot. This also stops it from getting mixed up with potions, since drop pot has a habit of dropping potions as well.

Eventually, I plan to run a check in the rift to see if I have enough of the actual herbs I want before continuing. At this point, the alias assumes that you have enough herbs when you Send(outr .....) -- If you don't, then it'll continue anyway, but not make the amount that you wanted!


<aliases>
  <alias
   name="Brewing"
   match="^brew (\d+) (\D+)$"
   enabled="y"
   expand_variables="y"
   group="General"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>SetVariable ("brewamt" , %1 * 5)
SetVariable ("brewamt2" , GetVariable ("brewamt") * 2)
SetVariable ("brewtype", "%2")

ColourNote ("white", "black", "Just checking! " .. GetVariable ("brewamt") .. " " .. GetVariable ("brewamt2") .. " " .. GetVariable("brewtype"))

if GetVariable ("brewtype") == "health" then
 Send ("outr " .. GetVariable("brewamt") .. " valerian")
 Send ("outr " .. GetVariable("brewamt") .. " goldenseal")
 Send ("outr " .. GetVariable("brewamt") .. " ginseng")
 Send ("outr " .. GetVariable("brewamt") .. " myrrh")
 Send ("inpot " .. GetVariable("brewamt") .. " valerian in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " goldenseal in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " ginseng in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " myrrh in @pot")
 Send ("drop @pot")
 Send ("boil @pot for health")
elseif GetVariable ("brewtype") == "mana" then
 Send ("outr " .. GetVariable("brewamt") .. " slipper")
 Send ("outr " .. GetVariable("brewamt") .. " bellwort")
 Send ("outr " .. GetVariable("brewamt") .. " hawthorn")
 Send ("outr " .. GetVariable("brewamt") .. " bloodroot")
 Send ("inpot " .. GetVariable("brewamt") .. " slipper in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " bellwort in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " hawthorn in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " bloodroot in @pot")
 Send ("drop @pot")
 Send ("boil @pot for mana")
elseif GetVariable ("brewtype") == "epidermal" then
 Send ("outr " .. GetVariable("brewamt2") .. " kuzu")
 Send ("outr " .. GetVariable("brewamt") .. " ginseng")
 Send ("outr " .. GetVariable("brewamt") .. " hawthorn")
 Send ("outr " .. GetVariable("brewamt") .. " bloodroot")
 Send ("inpot " .. GetVariable("brewamt2") .. " kuzu in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " ginseng in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " hawthorn in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " bloodroot in @pot")
 Send ("drop @pot")
 Send ("boil @pot for epidermal")
elseif GetVariable ("brewtype") == "immunity" then
 Send ("outr " .. GetVariable("brewamt") .. " sac")
 Send ("outr " .. GetVariable("brewamt") .. " ash")
 Send ("outr " .. GetVariable("brewamt2") .. " echinacea")
 Send ("inpot " .. GetVariable("brewamt") .. " sac in @pot")
 Send ("inpot " .. GetVariable("brewamt") .. " ash in @pot")
 Send ("inpot " .. GetVariable("brewamt2") .. " echinacea in @pot")
 Send ("drop @pot")
 Send ("boil @pot for immunity")
end</send>
  </alias>
</aliases>
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 21 Dec 2011 04:01 AM (UTC)
Message
You know, you could simplify that somewhat by just using Lua variables, like this:


<aliases>
  <alias
   name="Brewing"
   match="^brew (\d+) (\D+)$"
   enabled="y"
   expand_variables="y"
   group="General"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>brewamt = %1 * 5
brewamt2 = brewamt * 2
brewtype = "%2"

ColourNote ("white", "black", "Just checking! " .. brewamt .. " " .. brewamt2 .. " " .. brewtype)

if brewtype == "health" then
 Send ("outr " .. brewamt .. " valerian")
 Send ("outr " .. brewamt .. " goldenseal")
 Send ("outr " .. brewamt .. " ginseng")
 Send ("outr " .. brewamt .. " myrrh")
 Send ("inpot " .. brewamt .. " valerian in @pot")
 Send ("inpot " .. brewamt .. " goldenseal in @pot")
 Send ("inpot " .. brewamt .. " ginseng in @pot")
 Send ("inpot " .. brewamt .. " myrrh in @pot")
 Send ("drop @pot")
 Send ("boil @pot for health")
elseif brewtype == "mana" then
 Send ("outr " .. brewamt .. " slipper")
 Send ("outr " .. brewamt .. " bellwort")
 Send ("outr " .. brewamt .. " hawthorn")
 Send ("outr " .. brewamt .. " bloodroot")
 Send ("inpot " .. brewamt .. " slipper in @pot")
 Send ("inpot " .. brewamt .. " bellwort in @pot")
 Send ("inpot " .. brewamt .. " hawthorn in @pot")
 Send ("inpot " .. brewamt .. " bloodroot in @pot")
 Send ("drop @pot")
 Send ("boil @pot for mana")
elseif brewtype == "epidermal" then
 Send ("outr " .. brewamt2 .. " kuzu")
 Send ("outr " .. brewamt .. " ginseng")
 Send ("outr " .. brewamt .. " hawthorn")
 Send ("outr " .. brewamt .. " bloodroot")
 Send ("inpot " .. brewamt2 .. " kuzu in @pot")
 Send ("inpot " .. brewamt .. " ginseng in @pot")
 Send ("inpot " .. brewamt .. " hawthorn in @pot")
 Send ("inpot " .. brewamt .. " bloodroot in @pot")
 Send ("drop @pot")
 Send ("boil @pot for epidermal")
elseif brewtype == "immunity" then
 Send ("outr " .. brewamt .. " sac")
 Send ("outr " .. brewamt .. " ash")
 Send ("outr " .. brewamt2 .. " echinacea")
 Send ("inpot " .. brewamt .. " sac in @pot")
 Send ("inpot " .. brewamt .. " ash in @pot")
 Send ("inpot " .. brewamt2 .. " echinacea in @pot")
 Send ("drop @pot")
 Send ("boil @pot for immunity")
end</send>
  </alias>
</aliases>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,166 posts)  Bio   Forum Administrator
Date Reply #5 on Wed 21 Dec 2011 04:15 AM (UTC)

Amended on Wed 21 Dec 2011 04:16 AM (UTC) by Nick Gammon

Message
Another thing you could do is "roll your own" replacements. That way you can just put all the brewing commands into one long multi-line send, and let a simple find-and-replace pop the right values in for you, like this:


<aliases>
  <alias
   name="Brewing"
   match="^brew (\d+) (\D+)$"
   enabled="y"
   expand_variables="y"
   group="General"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
replacements = {
  brewamt = %1 * 5,
  brewamt2 = brewamt * 2,
  brewtype = "%2",
}

function fixup_sends (what)
  return string.gsub (what, "%%((%%w+)%%)", replacements)
end -- fixup_sends

if brewtype == "health" then

Send (fixup_sends ([[
outr (brewamt) valerian
outr (brewamt) goldenseal
outr (brewamt) ginseng
outr (brewamt) myrrh
inpot (brewamt) valerian in @pot
inpot (brewamt) goldenseal in @pot
inpot (brewamt) ginseng in @pot
inpot (brewamt) myrrh in @pot
drop @pot
boil @pot for health ]]))

elseif brewtype == "mana" then

Send (fixup_sends ([[
outr (brewamt) slipper
outr (brewamt) bellwort
outr (brewamt) hawthorn
outr (brewamt) bloodroot
inpot (brewamt) slipper in @pot
inpot (brewamt) bellwort in @pot
inpot (brewamt) hawthorn in @pot
inpot (brewamt) bloodroot in @pot
drop @pot
boil @pot for mana ]]))

elseif brewtype == "epidermal" then

Send (fixup_sends ([[
outr (brewamt2) kuzu
outr (brewamt) ginseng
outr (brewamt) hawthorn
outr (brewamt) bloodroot
inpot (brewamt2) kuzu in @pot
inpot (brewamt) ginseng in @pot
inpot (brewamt) hawthorn in @pot
inpot (brewamt) bloodroot in @pot
drop @pot
boil @pot for epidermal ]]))

elseif brewtype == "immunity" then

Send (fixup_sends ([[
outr (brewamt) sac
outr (brewamt) ash
outr (brewamt2) echinacea
inpot (brewamt) sac in @pot
inpot (brewamt) ash in @pot
inpot (brewamt2) echinacea in @pot
drop @pot
boil @pot for immunity ]]))

end</send>
  </alias>
</aliases>


In this case I use (brewamt) or (brewamt2) as "variables". Then a string.gsub finds them, and looks up the replacement in a table.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Zerrif   (5 posts)  Bio
Date Reply #6 on Thu 22 Dec 2011 02:35 PM (UTC)
Message
Oh wow, didn't even know I could do that! Wow, that's way more efficient and clean looking. Thanks!
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.


20,327 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.