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 ➜ Alias in Lua

Alias in Lua

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


Posted by Halig   Portugal  (123 posts)  Bio
Date Sat 14 Feb 2015 02:06 PM (UTC)
Message
Hi to all. I have an alias in Lua, and i couldn't figure this out.

<aliases>
<alias
match="^-arma -(.*)"
enabled="y"
expand_variables="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>new_1 = "%1";

wield = GetVariable("wield");
container = GetVariable("container");

if (new_1 == "nada") then
print("Changing to nothing")
else (wield ~= "nada")
Print("Removing: ", wield)
Send("remove " .. wield);
Send("put " .. wield .. " " .. container);
SetVariable("wield", "nada");
return;
end

if (wield != new_1) then
Print("Changing to: ", new_1)
else (wield != "nada")
Send("rem " .. wield);
Send("put " .. wield .. " " .. container);
Send("get " .. new_1 .. " " .. container);
Send("wield " .. new_1);
SetVariable("wield",new_1);
end

if (new_1 == wield) then
Print("Already using that!")
return;
end </send>
</alias>
</aliases>

It states:

Error number: 0
Event: Compile error
Description: [string "Alias: "]:9: syntax error near 'Print'
Called by: Immediate execution

I have one MushClient variable, wield, that is the variable egarding the weapon i'm wielding. When i type the alias, it goes to the can and graves the %1 that i typed in.
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #1 on Sat 14 Feb 2015 02:19 PM (UTC)
Message
Shouldn't there be a space between print and the parentheses?

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #2 on Sat 14 Feb 2015 02:34 PM (UTC)
Message
Hi. I've changed that and the error persists.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 14 Feb 2015 10:25 PM (UTC)

Amended on Sat 14 Feb 2015 10:26 PM (UTC) by Nick Gammon

Message
This is the error line (line 9):


else (wield ~= "nada")


That is not valid syntax. You mean "elseif" in this case. You also need a "then".


if (wield != new_1) then


That is C syntax. You need:


if (wield ~= new_1) then


Also while the MUSHclient functions (like Send) are capitalized, the Lua functions (like print) are not. Alternatively, use Note instead of print.

So, I made quite a few changes, resulting in this:


<aliases>
  <alias
   match="^-arma -(.*)"
   enabled="y"
   expand_variables="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

new_1 = "%1";

wield = GetVariable("wield")
container = GetVariable("container")

if new_1 == "nada" then
  print("Changing to nothing")
elseif wield ~= "nada" then
  print("Removing: ", wield)
  Send("remove " .. wield)
  Send("put " .. wield .. " " .. container)
  SetVariable("wield", "nada")
  return;
end

if wield ~= new_1 then
  print("Changing to: ", new_1)
elseif wield ~= "nada" then
  Send("rem " .. wield)
  Send("put " .. wield .. " " .. container)
  Send("get " .. new_1 .. " " .. container)
  Send("wield " .. new_1);
  SetVariable("wield",new_1)
end

if new_1 == wield then
  print("Already using that!")
  return
end 
</send>
  </alias>
</aliases>


Please compare to your original. I suggest using indentation in future to make things clearer.

Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- Nick Gammon

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

Posted by Halig   Portugal  (123 posts)  Bio
Date Reply #4 on Fri 20 Feb 2015 09:39 AM (UTC)
Message
I'm sorry for the late answer. I manage to put that to work, but have to take off some lines. Thank you Nick.
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.


17,874 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.