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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Makya
Newbie


Joined: 28 Nov 2011
Posts: 5

PostPosted: Tue Dec 06, 2011 4:35 pm   

Help With #IF actions
 
I am trying to write a #IF command string that sometimes needs to give two reactions. When I use the normal line break ';' inside the trigger it spits out the line:
Code:
work @Atk1;#alarm +6 {Working_2}

..which the mud cannot use. Are there any solutions other than turning it into an alias to reference first?

Code:
#If (@Perc >= 101) {~work @Fin1} {#If (@Perc <= 85) {~work @Atk2;#alarm +11 {Working_2}} {#If (@Perc > 85 AND @Perc <= 99) {~work @Atk1;#alarm +6 {Working_2}} {#If (@Perc = 100) {~work @Atk1;#alarm +6 {Working_2}}}}}
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Tue Dec 06, 2011 8:32 pm   
 
The problem is where you are quoting the work command with ~. Removing the ~ or replacing with #send should solve your problem.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Tue Dec 06, 2011 9:08 pm   
 
Wouldn't something like this be easier?

Code:
#switch (@Perc >=101) {
  #sendraw {work @Fin1}
  }
  (@Perc > 85) {
  #sendraw {work @Atk1}
  #alarm +6 {Working_2}
  }
  (@Perc <=85) {
  #sendraw {work @Atk2}
  #alarm +11 {Working_2}
  }
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Wed Dec 07, 2011 8:36 am   
 
Fizgar wrote:
The problem is where you are quoting the work command with ~. Removing the ~ or replacing with #send should solve your problem.


That shouldn't be a problem. Ideally, he'd want to use #SENDRAW, and not #SEND because #SENDRAW will send it as the MUD command rather than an alias. ~work means to send [b]work[\b] without client alias interference, and has been used in many scripts before.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Dec 07, 2011 2:22 pm   
 
I'm trying to find the section of the documentation that mentions the ~ syntax, if there is one. Can anyone else find it?

My vague recollection is that the ~ syntax is good for the command line, but not recommended for scripts. But I'm not at all certain about that. In any case, #SENDRAW is definitely the safest syntax for this situation.
Reply with quote
Fizgar
Magician


Joined: 07 Feb 2002
Posts: 333
Location: Central Virginia

PostPosted: Wed Dec 07, 2011 3:17 pm   
 
While using ~ shouldn't be a problem, it is when used to quote a word inside a #if statement with multiple commands separated by ;. Those are the results from my tests anyway. Also while #sendraw is 100% safe to use without causing other settings to fire, #send will work fine as long as there are no oninput triggers that have a pattern matching the text to be sent.
_________________
Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Wed Dec 07, 2011 5:33 pm   
 
The ~ is just to escape the alias name, so it doesn't get into an infinite loop of alias calls. The problem is that it's not parsing anything after ~work, so it won't recognize the ; as being a command separator. If you want to use a ~ to escape the alias, rather than using the #send command, you can't have any other commands on the same line. Also, I don't think #sendraw will work like others are suggesting, I assume you want the @Atk variables to expand?

This code should do what you want:
Code:
#If (@Perc >= 101) {
  ~work @Fin1
  } {
  #If (@Perc <= 85) {
    ~work @Atk2
    #alarm +11 {Working_2}
    } {
    #If (@Perc > 85 AND @Perc <= 99) {
      ~work @Atk1
      #alarm +6 {Working_2}
      } {
      #If (@Perc = 100) {
        ~work @Atk1
        #alarm +6 {Working_2}
        }
      }
    }
  }
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Fri Dec 09, 2011 11:14 pm   
 
Except the logic is wrong and you have two statements doing the absolute same thing. You should use #sendraw as well if you are sending something directly to the Mud.

Quote:
Also, I don't think #sendraw will work like others are suggesting, I assume you want the @Atk variables to expand?


It will work absolutely fine if you are coding properly. See my example above.
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sat Dec 10, 2011 4:49 am   
 
Huh, just tested it, and apparently #sendraw does expand variables. I thought the whole point of it was to send stuff directly to the mud without doing stuff like that. In fact, the documentation says: "The text is not echoed or parsed in any way." So yeah, your code should work, and the documentation should probably be updated...
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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