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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Fizban1216
Apprentice


Joined: 03 Feb 2007
Posts: 170

PostPosted: Wed Mar 17, 2010 4:08 pm   

Script question
 
Wrote the following script, just curious if it's the best way to have written it since I know the help files suggest against using #WAITFOR except when absolutely necessary and this is the first time I'd ever used it.

Code:
#TRIG {^The (%w) seems to be closed.$} {door = %1;open %1 %lastinput;#WAITFOR {It seems to be locked.$} 1000 {unlock  @door %lastinput;#WAITFOR {~*Click~*$} 1000 {open  @door %lastinput;#SEND %lastinput}} {#SEND %lastinput}}
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Mar 17, 2010 4:28 pm   
 
You should store %lastinput into a local variable and then use it in your #WAITFOR step. Also store the Door value into a local variable because this trigger might fire more than once with different matching door values. Because remember that while #WAITFOR is waiting, other commands, scripts, MUD input, etc can all be processed and by the time the #WAITFOR trigger fires, the %lastinput might have changed. If you use local variables and only read (not change) global variables, then there is no problem using #WAITFOR. So something like this:
Code:
Pattern: ^The (%w) seems to be closed.$
Script:
$door = %1
$lastinput = %lastinput
open %1 $lastinput
#WAITFOR {It seems to be locked.$} 1000 {
  unlock  $door $lastinput
  #WAITFOR {~*Click~*$} 1000 {
    open  $door $lastinput
    #SEND $lastinput
  }
} {#SEND $lastinput}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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