Gammon Forum
Entire forum
MUSHclient
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 (22,975 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):
That is not valid syntax. You mean "elseif" in this case. You also need a "then".
That is C syntax. You need:
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.
|
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.
15,484 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.