I'm very new and need help with this

Posted by Andromache on Sat 28 May 2011 01:54 AM — 13 posts, 44,173 views.

#0
Okay!
I'm trying to make alias like this
Send("tt %1")
SetVariable("t", "%1")
If t == Arcane
Send("enemy Saboteur 100")
else ("send enemy %1")
end--if
USA #1
And what's the problem? ;)
#2
Compile error
World: Avalon
Immediate execution
[string "Alias: "]:3: '=' expected near 't'

See I try to type t Arcane
to target Arcane
so my attacks like brilliance him
but I have to enemy Saboteur for my rituals to affect him cuz his name is Saboteur
Amended on Sat 28 May 2011 02:09 AM by Andromache
USA #3
Thanks. Put simply, you have a couple syntax errors and semantics errors. I'll mark and explain each one.

Send("tt %1")
SetVariable("t", "%1")
If t == Arcane             -- (1, 2, 3)
Send("enemy Saboteur 100")
else ("send enemy %1")     -- (4)
end--if


(1) "If" must be lowercase - Lua is case-sensitive.
(2) The 't' Lua variable isn't defined or assigned to anywhere. There are two kinds of variables in MUSHclient: script variables, which are native to the script, and client variables, which you get/set using SetVariable and GetVariable. They are very different and entirely separate, and you usually want script variables except in a few instances.
(3) The word 'Arcane' here is unquoted. Lua will assume it's a variable, which I'm pretty sure isn't what you want. You want to add quotes around it so Lua knows it's plain data.
(4) Else what? Else a string in parentheses. You probably wanted to Send that string.

Fixed up:
Send("tt %1")
local t = "%1"  -- script variable
if t == "Arcane"
  Send("enemy Saboteur 100")
else
  Send("send enemy %1")
end


Also, anything after -- on a line is a comment, which Lua ignores. It's handy for making notes in your code.
USA Global Moderator #4
Not exactly fixed up. You also need "then" at the end of the if line or you'll have another syntax error.

http://www.lua.org/pil/4.3.1.html
Amended on Sat 28 May 2011 03:23 AM by Fiendish
#5
Thanks! Now to figure out how I change from using client variables for my attacks! because all my other aliases still use those kind: point nullify @t

Sorry I'm new new!
USA #6
Well, what you just mentioned is one of those good uses of client variables. Client and script variables both would work well for this, but client variables have the advantages of being relatively simple and being editable from the Variables dialog. They're good for persistent data.
#7
So How would I make it work for client variables?
Or should I just try to learn how to change all my variables in my aliases to script variables so my new target/enemy alias would work with what you helped me with?
USA #8
You can mix client and script variables, you just have to remember that SetVariable('t', 42) doesn't change the script variable 't'.

Also, I think I fixed your alias incorrectly. Let me fix that again:
Send("tt %1")

local t = "%1"
SetVariable("t", t) -- save as target

if t == "Arcane" then
  Send("enemy Saboteur 100")
else
  Send("send enemy %1")
end

I realized that you probably did want to save the target as a client variable so your other stuff can get at it. It's also stored as a temporary client variable here (local t) so it's easier to actually use in the script.

[EDIT]: Missing then. :|
Amended on Sat 28 May 2011 04:53 AM by Twisol
USA Global Moderator #9
Quote:
Also, I think I fixed your alias incorrectly. Let me fix that again:

You missed "then" again. :)
USA #10
>_<
#11
Send("tt %1")

local t = "%1"
SetVariable("t", t) -- save as target

if t == "Arcane" then
Send("enemy Saboteur 100")
else
Send("send enemy %1")
end



Crap! for some reason it still try to enemy Arcane instead of Saboteur



Thank you guys for all your help! Sorry I keep posting on this one little problem.
Amended on Sat 28 May 2011 06:41 AM by Andromache
USA Global Moderator #12
I don't know the syntax of your MUD, but it seems like
Send("send enemy %1")

Should actually be
Send("enemy %1")