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
miegorengman
Novice


Joined: 05 Sep 2008
Posts: 34

PostPosted: Sat Jul 23, 2022 6:35 am   

temporary variable
 
is there a way to make a temporary variable within a script? I have a looooooooooooooooooong #sw that is already pretty bad, and instead of including a computation in each ifthen, I would like to run the calc once, assign the value to a temp variable, and then have the #sw refer to the temp variable.

what I hope to achieve

Code:
tempvar=%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))

#SW (tempvar>0)AND(tempvar<4) {Unskilled} (tempvar>3)AND(tempvar<10) {A tyro} (tempvar>9)AND(tempvar<18) {A novice}........



this is what I could end up with if I don't

Code:
#SW (%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))>0)AND(%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))<4) {Unskilled} (%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))>3)AND(%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))<10) {A tyro} (%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))>9)AND(%right(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),%match(%item(%exec("%countlist(@sniffsRawCounter)"),@petsRowNumber),"="))<18) {A novice}........


Thank you for reading
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 865
Location: USA

PostPosted: Sat Jul 23, 2022 6:18 pm   
 
If you mean that you want to get rid of it when you're done using it,
#UNVAR

Or, you can create one that has only local scope within the script:
#LOCAL
Reply with quote
chaossdragon
Apprentice


Joined: 09 Apr 2008
Posts: 148

PostPosted: Sat Jul 23, 2022 11:07 pm   
 
As Tarn said. Use "#LOCAL {tempVar}" then reference it with $tempVar

if you don't define it with #LOCAL it will dump the tempVar once the inital {script} is closed, so any further calls on it will be a 'new' tempVar and have no value.
Reply with quote
miegorengman
Novice


Joined: 05 Sep 2008
Posts: 34

PostPosted: Sun Jul 24, 2022 4:15 am   
 
thank you both, local worked great!
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