[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  The if command

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

The if command

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Val   (27 posts)  [Biography] bio
Date Sat 19 Mar 2011 03:53 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sat 19 Mar 2011 06:32 PM (UTC)  quote  ]
Message
Quote:
if x = ("not me") then

= is for assignment
for comparison you want ==

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Val   (27 posts)  [Biography] bio
Date Reply #2 on Sat 19 Mar 2011 11:21 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Manacle   (19 posts)  [Biography] bio
Date Reply #3 on Sun 20 Mar 2011 12:36 AM (UTC)  quote  ]
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)
[Go to top] top

Posted by Val   (27 posts)  [Biography] bio
Date Reply #4 on Sun 20 Mar 2011 01:23 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sun 20 Mar 2011 01:43 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Manacle   (19 posts)  [Biography] bio
Date Reply #6 on Sun 20 Mar 2011 04:52 AM (UTC)  quote  ]
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...
[Go to top] top

Posted by Val   (27 posts)  [Biography] bio
Date Reply #7 on Sun 20 Mar 2011 03:23 PM (UTC)  quote  ]
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
[Go to top] 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.


1,753 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]