|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Wed Jun 30, 2010 5:20 am
#WAITFOR & Local Variables |
Ok, I'm still learning CMUD scripting and I've come across a case of wanting to use a local variable as part of a pattern to #WAITFOR... however it doesn't seem to work. I'm just trying to find out if that should work and I'm doing something wrong, or if it doesn't work.
Example:
Code: |
$num_to_get = 3
#WAITFOR {You get $num_to_get rose petals from the bush.} 3000 {IF Success Commands} {Crud, I failed, so do something else!}
|
Always seems to fail, even if I do get 3 rose petals. So. Is it me, or is this feature/option not supported? |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Jun 30, 2010 5:45 am |
Temporary variables only exist within the scope of the setting that literally spawned them. #WAITFOR creates a thread beyond this particular setting, and so the temporary variable doesn't exist there even though the #WAITFOR was described in that setting's code.
I believe you would have to use some variation of #EXECUTE. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Wed Jun 30, 2010 3:57 pm |
Or just change it to a global variable, that would work as well, correct?
I mean, that would be much simpler all in all. |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Wed Jun 30, 2010 7:18 pm |
could you enclose the $localVar in %eval() within the #waitfor to force it work?
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Thu Jul 01, 2010 12:46 am |
Perhaps:
#WAITFOR %concat("You get ", $num_to_get, " rose petals from the bush.") 3000 {IF Success Commands} {Crud, I failed, so do something else!} |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Thu Jul 01, 2010 5:15 am |
I decided to go with the global variable, so I could use it in the output from the WAITFOR as well. But thanks for the answers,
|
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jul 01, 2010 3:35 pm |
Actually, #WAITFOR does not cause a "new" thread to spawn. When your script encounters the #WAITFOR command, the current thread goes into the background. But this means you can still use local variables just fine later in the script.
The issue is that #WAITFOR does not expand local variables within the pattern. However, the following script will work fine:
Code: |
$num_to_get = 3
#WAITFOR %concat("You get ",$num_to_get," rose petals from the bush.") 3000 {#SHOW Fired with $num_to_get} {Crud, I failed, so do something else!} |
|
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Thu Jul 01, 2010 4:22 pm |
ok, thanks Zugg, I'll change back to that then. That's much more efficient memory-wise I would guess.
|
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
|
|