Variable help

Posted by Dak on Thu 07 Sep 2006 05:26 PM — 5 posts, 20,163 views.

#0
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
Australia Forum Administrator #1
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
#2
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>
Australia Forum Administrator #3
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


Australia Forum Administrator #4
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.