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 ➜ Lua ➜ Prompt gagging and variables

Prompt gagging and variables

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


Posted by Tisorin   (15 posts)  Bio
Date Tue 21 May 2013 02:16 PM (UTC)
Message
Greetings,

Maybe other people asked this, but I didn't know what to search in the forum.

I have the following prompt when I type hp:

HP: 173/197 SP: 210/242 EP: 92/ 92

1. How I can save each value in in the variables hp, sp, ep?
2. How can I get only the hp variable when I type hp, and gag the prompt?
3. How can I get the hp variable's value when I hit f2, sp variable when I hit f3, and sp variable when I type f4?

Sorry, but I'm really new to this

Thank you in advance, Sorin
Top

Posted by Tisorin   (15 posts)  Bio
Date Reply #1 on Wed 22 May 2013 03:32 PM (UTC)
Message
So, after digging a bit, I think I found out how I can save the values to a variable, and I got this code:

<triggers>
<trigger
enabled="y"
expand_variables="y"
match="HP: */* SP: */* EP: */*"
send_to="12"
sequence="100"
>
<send>SetVariable("hp", "%1")
SetVariable("sp", "%3")
SetVariable("ep", "%5")</send>
</trigger>
</triggers>

Now, I have a little problem. I created an alias that it is supposed to give me the values of the hp variable, but it doesn't work:

<aliases>
<alias
match="checkhp"
enabled="y"
send_to="12"
sequence="100"
>
<send>GetVariable("hp")</send>
</alias>
</aliases>

What I'm doing wrong?

Thanks in advance, Sorin
Top

Posted by Tisorin   (15 posts)  Bio
Date Reply #2 on Thu 23 May 2013 04:21 PM (UTC)
Message
It is that complicated?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 24 May 2013 11:32 AM (UTC)
Message
It's almost perfect, except you are discarding the results of getting the variable. That is, this works:


<aliases>
  <alias
   match="checkhp"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>print (GetVariable("hp"))</send>
  </alias>
</aliases>



Note the use of "print".

Getting a variable in itself just returns the variable. You need to put it somewhere and use it.

eg



hp = tonumber (GetVariable("hp"))

if hp < 20 then
  print "ohno!"
end -- if

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Fri 24 May 2013 11:35 AM (UTC)
Message
Also, you don't need "expand variables" here:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="HP: */* SP: */* EP: */*"
   send_to="12"
   sequence="100"
  >
  <send>
SetVariable("hp", "%1")
SetVariable("sp", "%3")
SetVariable("ep", "%5")
</send>
  </trigger>
</triggers>



That just converts things like @hp into (almost) the equivalent of:



GetVariable ("hp")


However be warned that the expansion is done before the script is compiled, so you can't expand a variable you have only just set (in the same trigger/alias).

- Nick Gammon

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

Posted by Tisorin   (15 posts)  Bio
Date Reply #5 on Fri 24 May 2013 01:17 PM (UTC)
Message
Oh, it finally worked! Thank you
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.


19,882 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.