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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Tue Oct 26, 2004 7:24 pm   

Scanning a list for a variable value
 
Here's the situation:

  • a bunch of variables named "pAffliction" (e.g., pSensitivity, pRecklessness, pMasochism) that are 1 or 0, most of them 0 at any time
  • a list variable called lCurePrioritiesHerbs that has afflictions cured by herbs in priority order (e.g., "Recklessness|Sensitivity|...")
  • a string variable called sCurePriorityHerbs that I want to load with the name of the first affliction on the list that I have (that is, whose pVariable is 1)
  • similar pairs of variables, lCurePrioritiesSalves and sCurePrioritySalves, lCurePrioritiesElixirs and sCurePriorityElixirs, etc.


I need a way to load the variable for whichever kind of cure I'm currently working on. The trouble is that if I #forall over the list, I have no way to #abort out of that loop that I know of, that I can do inside an #if, because #abort inside #if only aborts the #if. #loop is not really any better.

This is what I've come up with, but it's slow and awkward. (Not fully tested yet, but passed basic testing.) It's an alias I might call as "prioritizeaffliction Herbs" (for instance):

Code:

#var %concat( "sCurePriority", %1) ""
iPriorityLoop = 1
iPriorityLength = %numitems( %eval( %concat( "@lCurePriorities", %1)))
#while (@iPriorityLoop <= @iPriorityLength) {
  sPriorityItem = %item( %eval( %concat( "@lCurePriorities", %1)), @iPriorityLoop)
  #if (%eval( %concat( "@p", @sPriorityItem)) = 1) {
    #var %concat( "sCurePriority", %1) @sPriorityItem
    iPriorityLoop = @iPriorityLength
    }
  #add iPriorityLoop 1
  }


Can anyone suggest a better, faster, less clunky way?
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Wed Oct 27, 2004 4:51 am   
 
This is how I abort out of a loop/forall based on a conditional:
Code:

#alias abort #noop
#forall @List {#if (Condition) {#alias abort {#abort}}
abort}


My modification to your alias:
Code:

#Alias AbortSequence {#noop}
#var sCurePriority%1 ""
#forall @{lCurePriorities%1} {#if (@{p%i} = 1) {#var sCurePriority%1 {%i}
#Alias AbortSequence {#Abort}}
AbortSequence}
Reply with quote
Theragil
Apprentice


Joined: 13 Feb 2004
Posts: 157
Location: USA

PostPosted: Wed Oct 27, 2004 10:06 pm   
 
Oh, that's sneaky. Thank you, that's brilliant.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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