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
NozzleImp
Newbie


Joined: 07 Mar 2016
Posts: 3

PostPosted: Mon Mar 07, 2016 7:59 pm   

Variable names within variable names?
 
Basically, I'm making an ally affliction tracker for an IRE mud, what this means is PC's are going to say something over a channel like so

Code:
(Web): Jack says, "Afflicting Dick: affliction1, affliction2."


Which I grab

Code:
^\(Web\)\: (\w+) says\, \"Afflicting (\w+)\: (\w+)\, (\w+)\.\"$

Code:
webcaller = %1
#if %ismember(@webcaller,@webteam) {
#if (%2 == @tar) {
#if (@webcaller == Jack) {jackwebqueue ="";#additem jackwebqueue %3;#additem jackwebqueue %4}}



And then if Dick is @tar, and Jack's attack goes through, it will move jackwebqueue to my own tracker variable.

This works for a few people, but it's unwieldy as anything, Jack is one of dozens that may be fighting with me at any given time, and for the first time someone new joins up, I need to add new #ifs for 6 or so similar (web): triggers, as well as dozens of attack messages.

I'm wondering if there is a way I could
Code:
#additem "@webcaller"webqueue %3

Or if there's actually some simpler method that I'm overlooking (I have zero experience with databases for instance, and I'm not sure if this is something that would be right up their alley.)

Any suggestions would be much appreciated, my searching has thus far produced little success.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Mar 07, 2016 10:21 pm   
 
I would suggest moving the check against @tar first for speed as that seems likely to ignore the most things. The check to see about the @webteam, skip the webcaller assignment and use %1 directly where needed. Finally use a single variable 'webqueue' like this:
#ADDKEY webqueue {%1} {%dups(%concat(%db(@webqueue,%1),"|",%3,"|",%4))}

You would have to supply information about how you do updates for me to suggest specific code for those updates. About all I can suggest now is read the help links I attached in my post.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
NozzleImp
Newbie


Joined: 07 Mar 2016
Posts: 3

PostPosted: Wed Mar 09, 2016 10:11 am   
 
Oh man, this looks like an absolutely perfect solution to my problem, and I've now made the @tar changes, thank you. I have hit something of a snag (unsurprisingly) in doing the updates.

Basically whenever anyone on my @webteam hits my target, I'd like to shift their value from the webqueue to my @afflicted string list variable, which I've been doing with this.

Code:
(\w+) hacks into @tar.* ruthlessly with a massive halberd.

Code:
#if (%1 == Jack) {#forall @jackwebqueue {#additem afflicted %i};jackwebqueue = ""}


I figured I'd try roughly the same thing using your code with
Code:
#additem afflicted (%db(@webqueue,%1))

But this wound up putting both afflictions as a single value "|affliction1|affliction2" in @afflicted and I'm not quite sure how to split them up.

Thanks again for your time and help!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Mar 09, 2016 6:19 pm   
 
afflicted=%db(@webqueue,%1)
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
NozzleImp
Newbie


Joined: 07 Mar 2016
Posts: 3

PostPosted: Wed Mar 09, 2016 7:59 pm   
 
Because I am a scrub, I neglected to mention that I needed @afflicted to retain its previous entries, and also have no duplicates, however I took what I had, and mixed it up with the above and came up with,
Code:
afflicted2=%db(@webqueue,%1)
#forall @afflicted2 {#additem afflicted %i;#delitem afflicted2 %i}

Which seems to work just right, so unless you can see a glaring flaw in my plan (I'm on my work compy so can't test extensively) I'm going to call this Solved, and say thank you very much for your invaluable help, I would've googled till the cows come home and not come up with something this straightforward, you're an absolute diamond.
Reply with quote
shalimar
GURU


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

PostPosted: Wed Mar 09, 2016 11:18 pm   
 
Sounds like you need a database variable.
Or to make use of local variables as well.


Code:
#TR {~(Web~): ({@webTeam}) says, "Afflicting {@tar}: (*)."} {
    $this=%db(@webQueue, %1)
    $afflictions=%replace(%2, ", ", "|")
    #FORALL $afflictions {#ADDITEM $this %i}
    #ADDKEY webQueue %1 $this
    }
_________________
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