[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Alias in Lua
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Alias in Lua

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


Posted by Halig   Portugal  (123 posts)  [Biography] 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.
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] bio
Date Reply #2 on Sat 14 Feb 2015 02:34 PM (UTC)
Message
Hi. I've changed that and the error persists.
[Go to top] top

Posted by Nick Gammon   Australia  (21,324 posts)  [Biography] 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
[Go to top] top

Posted by Halig   Portugal  (123 posts)  [Biography] 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.
[Go to top] 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.


3,160 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]