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 ➜ Variable help

Variable help

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


Posted by Dak   (2 posts)  Bio
Date Thu 07 Sep 2006 05:26 PM (UTC)
Message
I am kinda new to the scripting scene and I am trying to learn lua as I go. Anyway, I was wondering how I could make a variable I have stored as a global variable into something I can use as in a trig.

For example, my global variable is named "customer" (i change it often depending on who the customer is) and I want a few of my trigs to respond to commands coming from the named stored in that variable only. Is this possible and how can I do it?


Also, How do you make something run faster? I have an alias that is supposed to access the global variable and return a note with "<customer name> was your last customer" and it takes quite some time to return that. How can I speed this up?

Thanks for your help,

Dak
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 07 Sep 2006 09:12 PM (UTC)
Message
You need to distinguish between Lua variables and MUSHclient variables. One is held in the script engine "name space" and the other inside MUSHclient's world file.

Assuming for the moment that the variable is a MUSHclient variable, then the trigger simply look like this:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   expand_variables="y"
   match="You see @customer standing here"
   sequence="100"
  >
  </trigger>
</triggers>


Note the @<variablename> syntax, and "expand variables" is checked inside the trigger.

You can move to/from script and MUSHclient variables with GetVariable / SetVariable script functions. See the help file.

The alias should not take "quite some time" to execute. It should be able to handle thousands of aliases without noticeable speed degredation.

Can you paste the actual alias here please?

For how to do that, see this:

http://www.gammon.com.au/forum/?id=4776

- Nick Gammon

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

Posted by Dak   (2 posts)  Bio
Date Reply #2 on Thu 07 Sep 2006 09:21 PM (UTC)
Message
this is what the alias looks like... please be gentle if it is something completly stupid because I am not very good at this yet :P

<aliases>
<alias
name="customer"
match="customer"
enabled="y"
send_to="12"
sequence="100"
>
<send>customer = GetPluginVariable ("", "customer")

if customer == nil then
Tell ("you have had no customers recently.")
else
Tell (customer .. " was your last customer")

end

</send>
</alias>
</aliases>
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 07 Sep 2006 10:18 PM (UTC)
Message
Is this in a plugin? If not, you can use:


customer = GetVariable ("customer")


instead of:


customer = GetPluginVariable ("", "customer")


I see what you mean about it taking a long time - it seemed to take foreever for me. ;)

Then I realised, you had used Tell rather than Note.

What Tell does is put out a partial line, which you don't see until the newline. I only saw anything when I hit Enter on the keyboard. Do this instead:


if customer == nil then
  Note ("you have had no customers recently.")
else
  Note (customer .. " was your last customer")
end



- 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 Thu 07 Sep 2006 10:21 PM (UTC)
Message
Another neat trick is to use the ideas presented in this thread:

http://www.gammon.com.au/forum/?id=4904

Using that you could just write:


if var.customer == nil then
  Note ("you have had no customers recently.")
else
  Note (var.customer .. " was your last customer")
end


You don't need to use GetVariable and SetVariable then. Read the post for more details.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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,522 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.