Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ The if command
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Val
(27 posts) Bio
|
| Date
| Sat 19 Mar 2011 03:53 PM (UTC) |
| Message
| Hi
I hope this is a quick one
in an alias I would like options on casting a spell with eiter of these two variables @target (preset with "me" or "not me" depending on the spell) and @target2 (a name I entered when I use "t *")
so if @target = me then cast @spellname at @target1
but if @target = not me then cast @spellname at @target2
Immediate execution
[string "Alias: "]:6: 'then' expected near '='
local target = GetVariable("target")
local target2 = GetVariable("target2")
local x = (".. target")
if x = ("not me") then
Send "cast @spellname at @target2"
if x = ("me") then
Send "cast @spellname at @target"
Thanks
Val | | Top |
|
| Posted by
| Fiendish
USA (2,547 posts) Bio
Global Moderator |
| Date
| Reply #1 on Sat 19 Mar 2011 06:32 PM (UTC) |
| Message
|
Quote: if x = ("not me") then
= is for assignment
for comparison you want == |
https://github.com/fiendish/aardwolfclientpackage | | Top |
|
| Posted by
| Val
(27 posts) Bio
|
| Date
| Reply #2 on Sat 19 Mar 2011 11:21 PM (UTC) |
| Message
| Thanks for that, I managed to take it a stage further but now I'm stuck again on something I know you will see as basic
currently I have the following -
local spellname = GetVariable("spellname1")
local targetme = GetVariable("targetme")
local target2 = GetVariable ("target2")
if x == "me" then Send ("cast " .. spellname, " on " .. targetme)
end
if x == "notme" then Send ("cast " .. spellname, " on " .. target2)
end
if x not == "notme" or "me" then Send ("cast " .. class, " " .. spellname, " on " .. target2)
end
The top part works, last line keeps throwing an error saying its expecting "then" near "not", so I gather it does not like the "or", help please?
Thank you
Val | | Top |
|
| Posted by
| Manacle
(28 posts) Bio
|
| Date
| Reply #3 on Sun 20 Mar 2011 12:36 AM (UTC) |
| Message
| Either this:
if x == "notme" then Send ("cast " .. spellname, " on " .. target2)
end
if x != "notme" or "me" then Send ("cast " .. class, " " .. spellname, " on " .. target2)
end
This:
if x == "notme" then
Send ("cast " .. spellname, " on " .. target2)
else
Send ("cast " .. class, " " .. spellname, " on " .. target2)
end
Or this, if you need more flexibility later:
Commands = {}
Commands["notme"] = "cast " .. spellname .. " on " .. target2
Commands.Default = "cast " .. class .. " " .. spellname .. " on " .. target2
tosend = Commands[x]
--this line sets your command to a default if it's something not already in Commands
if not tosend then tosend = Commands.Default end
Send(tosend)
| | Top |
|
| Posted by
| Val
(27 posts) Bio
|
| Date
| Reply #4 on Sun 20 Mar 2011 01:23 AM (UTC) |
| Message
| Thanks
I went for
if x == "me" then
Send ("cast " .. spellname, " on " .. target2)
else
Send ("cast " .. spellname, " on " .. target2)
end
I tried the != "notme" or "me" then Send ///
But I get n error, its looking for
17: 'then' expected near '!
If you can let me know what that might be it would help in the future.
the third one with the commands I did not really get yet, I'm still learning so I left it
Thanks for your help
Val | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Sun 20 Mar 2011 01:43 AM (UTC) |
| Message
| I don't think Manacle tested this bit (hey, I don't test all my posts either!) ...
if x != "notme" or "me" then Send ("cast " .. class, " " .. spellname, " on " .. target2)
end
For a start, break it into lines to look neater. Second "not equal" is ~= not !=. (The != form is from C which trips up C programmers).
Then you really want to re-test x, just saying 'or "me"' will have a different effect.
And you seem to be mixing up commas and concatenation. For neatness, use one or the other.
So in total:
if x ~= "notme" and x ~= "me" then
Send ("cast ", class, " ", spellname, " on ", target2)
end
So this spell is cast if x is neither "me" nor "notme" if that is what you intended. But if not, I prefer the else. If you are doing this *or* that, then use if/else.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Manacle
(28 posts) Bio
|
| Date
| Reply #6 on Sun 20 Mar 2011 04:52 AM (UTC) |
| Message
|
Nick Gammon said:
I don't think Manacle tested this bit (hey, I don't test all my posts either!) ...
if x != "notme" or "me" then Send ("cast " .. class, " " .. spellname, " on " .. target2)
end
For a start, break it into lines to look neater. Second "not equal" is ~= not !=. (The != form is from C which trips up C programmers).
I think half of the effort I spend on Lua plugins is translation. I might add that another ten percent is lamenting the loss of my ternary operator. Tasty, tasty ternary... | | Top |
|
| Posted by
| Val
(27 posts) Bio
|
| Date
| Reply #7 on Sun 20 Mar 2011 03:23 PM (UTC) |
| Message
| Hi
Thanks for the explination, and thanks to both of you for your help, the method i'm using seems to be doing the trick
Val | | 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.
25,444 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top