Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ I'm very new and need help with this

I'm very new and need help with this

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


Posted by Andromache   (7 posts)  Bio
Date Sat 28 May 2011 01:54 AM (UTC)
Message
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
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Sat 28 May 2011 02:03 AM (UTC)
Message
And what's the problem? ;)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Andromache   (7 posts)  Bio
Date Reply #2 on Sat 28 May 2011 02:06 AM (UTC)

Amended on Sat 28 May 2011 02:09 AM (UTC) by Andromache

Message
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
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Sat 28 May 2011 03:11 AM (UTC)
Message
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.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #4 on Sat 28 May 2011 03:21 AM (UTC)

Amended on Sat 28 May 2011 03:23 AM (UTC) by Fiendish

Message
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

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Andromache   (7 posts)  Bio
Date Reply #5 on Sat 28 May 2011 03:43 AM (UTC)
Message
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!
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #6 on Sat 28 May 2011 03:52 AM (UTC)
Message
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.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Andromache   (7 posts)  Bio
Date Reply #7 on Sat 28 May 2011 04:04 AM (UTC)
Message
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?
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #8 on Sat 28 May 2011 04:26 AM (UTC)

Amended on Sat 28 May 2011 04:53 AM (UTC) by Twisol

Message
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. :|

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #9 on Sat 28 May 2011 04:51 AM (UTC)
Message
Quote:
Also, I think I fixed your alias incorrectly. Let me fix that again:

You missed "then" again. :)

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #10 on Sat 28 May 2011 04:53 AM (UTC)
Message
>_<

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Andromache   (7 posts)  Bio
Date Reply #11 on Sat 28 May 2011 06:40 AM (UTC)

Amended on Sat 28 May 2011 06:41 AM (UTC) by Andromache

Message
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.
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #12 on Sat 28 May 2011 06:50 AM (UTC)
Message
I don't know the syntax of your MUD, but it seems like
Send("send enemy %1")

Should actually be
Send("enemy %1")


https://github.com/fiendish/aardwolfclientpackage
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.


31,002 views.

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

Go to topic:           Search the forum


[Go to top] top

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