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


Joined: 04 Jan 2010
Posts: 5

PostPosted: Sun May 26, 2013 3:05 pm   

Getting items from the string list
 
Greetings,

I'm wondering if there is a possibility to get all occurrences (in case where there are more than one in string list) of an item from the string list returning it's number in the list (something like %ismember but to return more items)?

Eg.

$string = a|b|c|d|a|e|f|a|a

%ismember(a,$string) will return only one item (1 to be exact) ignoring rest (so 5, 8 and 9). Anyone know how to return all of them? Thanks in advance.

Regards,
V.
Reply with quote
shalimar
GURU


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

PostPosted: Sun May 26, 2013 4:11 pm   
 
#LOCAL $place $list
#FORALL $string {$place=($place+1);#IF (%i=a) {#ADDITEM $list %i}}
#SAY $list
_________________
Discord: Shalimarwildcat
Reply with quote
Vaxon
Newbie


Joined: 04 Jan 2010
Posts: 5

PostPosted: Sun May 26, 2013 4:27 pm   
 
This unfortunately does not work (still returns only first occurrence).

I think I explained my issue incorrectly.

I've got string list @allM with names of known players, @alloM with short description of those (in the same order so eg. fifth item in @allM is correlated to fifth item in @alloM). As none of those are unique duplicates can be found in both of those string lists. What I need:

Example:

@allM = John|Steve|Paul|Roderick
@alloM = short fat dwarf|big stubborn elf|short fat dwarf|little big man

Pattern:
Short fat dwarf.

What I want to see:
Short fat dwarf (John, Paul).

Hope it's clearer now.

PS. Got it working - just needed to replace last %i with %item(@list,$place).
Reply with quote
shalimar
GURU


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

PostPosted: Sun May 26, 2013 6:38 pm   
 
Sorry bout that, i had just woken up.
#FORALL $string {$place=($place+1);#IF (%i=a) {#ADDITEM $list $place}}

was how i meant it to be, then $list contains all the %item numbers it occurs at

but if you got it working for you, great
_________________
Discord: Shalimarwildcat
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Mon May 27, 2013 2:55 am   
 
Vaxon why not just create a data record instead of parallel lists (arrays)?

Example:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="allMembers" type="Record" copy="yes">
    <value>John=short fat dwarf|Steve=big stubborn elf|Paul=short fat dwarf|Roderick=little big man</value>
    <json>{"Roderick":"little big man","Paul":"short fat dwarf","John":"short fat dwarf","Steve":"big stubborn elf"}</json>
  </var>
  <alias name="FindDesc" copy="yes">
    <value>#local $list
$value = %trim(%params)
#loopdb @allMembers
{
  #if ($value == %val)
  {
    #additem $list %key
  }
}
#print {$value [%expandlist($list,", ")]}</value>
  </alias>
</cmud>


Entering "FindDesc short fat dwarf" returns the following:

short fat dwarf [John, Paul]
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