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
Wanderer


Joined: 05 Sep 2008
Posts: 52

PostPosted: Tue Aug 09, 2022 6:10 am   

using temp variables / #local to create new variable and/or update variables
 
i am trying to make a one and done counter trigger that creates and/or updates.

my mud sends You think your language#mouse skill has improved.

so I simply use (*) to grab language#mouse as %1

I have also found that some characters break my scripts, namely apostrophe, pound sign/hashtag, and blanks, so my first step was to use use #local

Code:
#local $fixedIt
$fixedIt=%replace(%replace(%replace(%1,"''",""),"#","_")," ","_")



so now my %1 of language#mouse has be come $fixedIt language_mouse


now I want to create/update a variable and I have tried the following scripting and probably more I don't recall:

Code:
#var $fixedIt (@$fixedIt+1) {} {skillNumbers}

#var {$fixedIt} (@{$fixedIt}+1) {} {skillNumbers}

#var ($fixedIt) ($fixedIt+1) {} {skillNumbers}




assuming everything works how I want it to the script should effectively read

Code:
#var language_mouse (@language_mouse+1) {} {skillNumbers}



but somehow the $fixedIt isn't translating directly into language_mouse. any suggestions?


thanks for reading[/code]
Reply with quote
mikeC130
Apprentice


Joined: 03 Jul 2006
Posts: 110

PostPosted: Tue Aug 09, 2022 1:53 pm   
 
There are a couple issues. First, as a general rule, just use your local variable $FixedIt for a single purpose - capturing and storing the variable name. Use other variables your math. Splitting it up into separate steps makes it much easier to read AND TROUBLESHOOT (especially for old guys like me, who can barely tell curly and regular brackets apart, and then barely remember the differences).

$TempInt = @{$fixedIt}
$TempInt=($TempInt+1)
will grab the variable you want and increment the value, storing it in $TempInt

Now we come to the bigger issue - while you can REFERENCE the variable indirectly, it doesn't seem that you can ASSIGN it. So you can pull the data out, but can't change the value of the variable itself.

{$fixedIt}=$TempInt
#var {$fixedIt}=$TempInt

Both of these cause the trigger to fail when compiling. Perhaps Shalimar or one of the other experts can chime in on how to manage an indirect assignment,

Mike
Reply with quote
miegorengman
Wanderer


Joined: 05 Sep 2008
Posts: 52

PostPosted: Tue Aug 09, 2022 5:20 pm   a hackey fix?
 
Thank you Mike, every little bit helps. I had something come to me while I was reading your post...seems maybe hackey, or may its just me finally understanding how coding works a little better, but %exec($fixedIt) seems to be the solve. the following allows #local variables to be used within my #var command

#var %exec($fixedIt) (@{%exec($fixedIt)}+1) {} {skillNumbers}

also, thank you for inspiring me to learn how to increase the font size so the brackets are easier to read...sadly cannot be combined with the code business
Reply with quote
mikeC130
Apprentice


Joined: 03 Jul 2006
Posts: 110

PostPosted: Tue Aug 09, 2022 7:19 pm   
 
Glad you got it worked out. The use of the exec function is a bit of black magic to me - I can read through and figure out what it MEANS, but I am not nearly knowledgeable enough in the workings of CMUD's parser to figure out why it is NEEDED.

Mike
Reply with quote
miegorengman
Wanderer


Joined: 05 Sep 2008
Posts: 52

PostPosted: Wed Aug 10, 2022 1:12 am   
 
Hahahaha....same
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Wed Aug 10, 2022 4:02 pm   
 
Due to the indirect way they are referenced, exec forces things to evaluate/be parsed that otherwise wouldn't.

Personally, I would use a dbVar to handle storage, which means the local variables can be used directly.

Code:
$name=%replace(%replace(%replace(%1,"''",""),"#","_")," ","_")
$value=(%db(@skills, $name)+1)
#ADDKEY skills $name $value


#LOCAL is only needed when the variable is defined in a subscript (such as an #IF or a #LOOP) rather than in the main body of code. It's a scoping issue. Local variables only exist within the {code block {and subscripts thereof}} that they are first defined.
_________________
Discord: Shalimarwildcat
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