Alias in Lua

Posted by Halig on Sat 14 Feb 2015 02:06 PM — 5 posts, 23,624 views.

Portugal #0
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.
USA #1
Shouldn't there be a space between print and the parentheses?
Portugal #2
Hi. I've changed that and the error persists.
Australia Forum Administrator #3
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.
Amended on Sat 14 Feb 2015 10:26 PM by Nick Gammon
Portugal #4
I'm sorry for the late answer. I manage to put that to work, but have to take off some lines. Thank you Nick.