Lua Script variables

Posted by Errigour on Mon 18 Jul 2011 03:43 PM — 10 posts, 37,743 views.

USA #0
I want the following code to use i inside the "" qoute marks instead of i.


for i= 1, 7 do
AddAlias("", "i", "cast '@castingspell' @target", alias_flag.Enabled, alias_flag.eExpandVariables, "")
end
USA #1
I also want to use AddAlias with more then one flag etc alias_flag.Enabled and alias_flag.eExpandVariables
USA #2
I also wanna ask one more question here if it's ok.
I want to make an alias
heal *
and if %1 is a number then I want it
to execute a for loop and if %1 is
a word/character then I want it to
execute normaly
USA Global Moderator #3
In reverse order...


if tonumber("%1") then
  -- do stuff here if %1 is a number
else
  -- do stuff here if %1 is not a number
end


Flags are just magic numbers staggered in such a way that they can be added together. So add them together.

I don't understand your question.
Amended on Mon 18 Jul 2011 06:29 PM by Fiendish
Australia Forum Administrator #4
Errigour said:

I want the following code to use i inside the "" qoute marks instead of i.


Does this help?

http://www.gammon.com.au/scripts/doc.php?lua=string%20literals
Australia Forum Administrator #5
Errigour said:

I also want to use AddAlias with more then one flag etc alias_flag.Enabled and alias_flag.eExpandVariables


You might find addxml easier to use:

http://www.gammon.com.au/forum/?id=7123

eg.


require "addxml"
addxml.alias {  
                match = "k", 
                enabled = true,
                expand_variables = true,
                send = "kick @target",
                sequence = 100,
              }

Amended on Mon 18 Jul 2011 08:50 PM by Nick Gammon
USA #6

alias:heal *

if tonumber("%1") then
  if %1 > 0 then
    for i = 1, %1 do
    Send("heal heal")
    end
  end
else
  Note("heal")
end

I used the code above and when I just type heal it would send
heal to to mud instead of sending Note("heal"). and if I typed heal with a space "heal " or "heal " it sends an error
message my way.

[string "Alias: "]:2: unexpected symbol near '>'

I want to send Send("heal %1") if %1 is a space or a character and it seems to me tonumber recognizes that %1 is a number even if its an empty space.

MUSHclient
It ignores the command all together if I type heal without an argument also and it works if its a character but not
when it's a blank space. So I used "heal*" to fix the ignoring script part and now it just gives me an error when I type heal by itself. I removed the if statement if %1 > 0
and i get this error when typing heal by itself.


[string "Alias: "]:2: unexpected symbol near 'do'


So The Above works accept it doesn't work when I just type heal and leave * null. Is there a better way to do what I am trying to do without sending me an error message when I type heal with a null %1 character?
Australia Forum Administrator #7
Errigour said:

I used the code above and when I just type heal it would send
heal to to mud instead of sending Note("heal").


I expect that because your alias matches: heal<space><something> and typing "heal" does not have a space.

Errigour said:

... if I typed heal with a space "heal " or "heal " it sends an error message my way.


I expect that too. It replaces %1 by whatever you had after the space. So if there is nothing after the space it will have given you:


 if > 0 then
    for i = 1, do
    Send("heal heal")
    end
  end


You really need to convert %1 to a number while it is in quotes. eg.


local count = tonumber ("%1")

if count then  -- that is, if it is a number
    for i = 1, count do
      Send("heal heal")
    end
else
  Note ("heal")
end -- if


Also:

Template:faq=50
Please read the MUSHclient FAQ - point 50.
Amended on Fri 22 Jul 2011 11:27 AM by Nick Gammon
USA #8
Thanks I wanted to intercept Null commands from the mud
itself so that help big time and also regular that regular
expression forum helped some.

Can I ask you if there is a way to configure mush client to not ignore aliases such as "heal *" when I only type "heal"
by itself.
Australia Forum Administrator #9
Yes, the FAQ point 50 describes exactly that.