Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sat Sep 17, 2005 11:11 am   

IF Command
 
Can anyone tell me how to set an IF command in an alias, so that if %4 is a certain word, if performs a set action, and if not, ignores it an moves on.
I've tried

Code:
if (%4 = porcupine) {get porcupine}{}


but its not working.

Thanks
Ferga
Reply with quote
Maruchan
Newbie


Joined: 16 Sep 2005
Posts: 5

PostPosted: Sat Sep 17, 2005 11:58 am   
 
Perhaps, #if %word( "porcupine", %4) {get porcupine} help there.

Edit: Hrm, I didn't read it fully. You would need to store the fourth line somehow. I don't know how that would be done, without more understanding of what occurs before porcupine.
Reply with quote
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sat Sep 17, 2005 12:03 pm   
 
%4 is the fourth word in the input command. ie:
ALIASNAME %1 %2 %3 %4

so you shouldnt need to store the command. it seems to remember it for the duration of the alias' running.
Reply with quote
Orang
Apprentice


Joined: 22 Jul 2004
Posts: 118
Location: USA

PostPosted: Sat Sep 17, 2005 1:28 pm   
 
#ONINPUT {^(*)$} {#IF (%4 = "porcupine") {get porcupine}}
Reply with quote
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sat Sep 17, 2005 1:37 pm   
 
Doesnt work. just catches the alias into an eternal loop where it continually tries to pick up a body
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Sat Sep 17, 2005 4:34 pm   
 
if that was a copy and paste this woulda been simpler if anyone noticed that:
1) Fergal1982 said if and not #if
and
2) Fergal1982 said }{} not } {} (Fergal1982 missed a space)

This works for me

#IF (%4 = porcupine) {get porcupine} {}
_________________
http://www.Aardwolf.com
Reply with quote
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sat Sep 17, 2005 4:57 pm   
 
Vitae wrote:
if that was a copy and paste this woulda been simpler if anyone noticed that:
1) Fergal1982 said if and not #if
and
2) Fergal1982 said }{} not } {} (Fergal1982 missed a space)

This works for me

#IF (%4 = porcupine) {get porcupine} {}
Vitae,

Worked like a charm, you were right, i had missed the # (although i did pick up on it after my first post), but the space finally clinched it.

Thanks
Fergal
Reply with quote
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sat Sep 17, 2005 11:47 pm   
 
Ok, just one more thing. Often %4 isnt filled out at all (most of the time only %1 is filled out), now when i run the script, it keeps running the commands (get porcupine, etc) that ive put in as above.

Its not affecting the functioning of the script, but it looks untidy, is there any way to stop it doing that?

Thanks
Fergal
Reply with quote
psyber624
Newbie


Joined: 17 Sep 2005
Posts: 5

PostPosted: Sun Sep 18, 2005 4:10 am   
 
Well, id really need to see the whole body of this to be sure, but you could use nested ifs to take care of this situation. As follows:

#IF (%4 = '') {} {#IF (%4 = porcupine) {get porcupine}}
Reply with quote
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sun Sep 18, 2005 10:56 am   
 
hmmm. didnt work, heres the complete code (some of you will recognise from an earlier topic

Code:
#loop @toxins {
  harvest %2 %3 %4
  #wait 2000
  outflask syrup
  blend %2 with syrup
  #wait 2000
  inkit %2
  #IF (%4 = porcupine) {get porcupine} {}
  #IF (%4 = ogre) {get ogre} {}
  #IF (%4 = toad) {get toad} {}
  }
toxins = 0 0
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Sun Sep 18, 2005 3:42 pm   
 
You should always use quotes around strings. Here is what is happening when %4 is empty


#IF ( = Porcupine) {get porcupine}
Since there is nothing to evaluate on the left side it again becomes this,
#IF (Porcupine) {get porcupine}
Which will always be true.

This is what you want,
#IF ("%4" = "Porcupine") {Get Porcupine}
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Sun Sep 18, 2005 5:07 pm   
 
Missed the "'s around Porcupine but never thought about for the %4
_________________
http://www.Aardwolf.com
Reply with quote
Fergal1982
Wanderer


Joined: 08 Aug 2005
Posts: 70

PostPosted: Sun Sep 18, 2005 7:46 pm   
 
Utterly fantastic. Works a treat.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net