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
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Mon Mar 21, 2016 4:06 pm   

String List #IF
 
Hey there,

I have a string list with entries such as:

Code:

name=Morality|owner=Sienar Fleet Systems|type=Providence-class Cruiser|planet=Unknown|dock=Unknown|date=03-21 10:42


What I'm trying to do is be able to search through the list and pull up the name, which I accomplished with this alias:

Code:

$shipsearch_target = %params

#PRINT
#PRINT %ansi(white)Database information:
#FORALL @ship_db {
  #IF (%upper(%i.name) = %upper($shipsearch_target)) {
    #SHOW %ansi(white)%format("&s : &s : &s : &s : &s : &s", %i.name, %i.owner, %i.type, %i.planet, %i.dock, %i.date)
  }
}
#PRINT


What I'm also trying to do now is add in a feature that performs an IF check to see if there is anything recorded in the @ship_db first. And if there is not, perform a different alias. However, I can't figure out where to put it. If I add it in the FORALL IF, it performs the alias for as many database entries as there are, and I can't seem to figure out how reference the %i.name field outside of the FORALL prior to running it. Any ideas?

Thanks!
Reply with quote
shalimar
GURU


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

PostPosted: Mon Mar 21, 2016 5:58 pm   
 
#LOCAL $key
#FORALL %dbkeys(@ship_db) {#IF (%match(%params, %db(%i, name))) {#ADDITEM $key %i}}

That would give you a list of all the keys with a sub key 'name' that matches what you pass it...
Which seems to be what you are looking for.

Perhaps if you restructured your db to use the name as the key instead you could bypass the need for a #FORALL:

$test=%db(@ship_db, %params)
#IF ($test) {alias1} {alias2}

Without an example of the db contents i can't help further.
_________________
Discord: Shalimarwildcat
Reply with quote
Xerakon
Apprentice


Joined: 10 May 2011
Posts: 111

PostPosted: Mon Mar 21, 2016 7:33 pm   
 
Hey shalimar,

Thanks so much! As always, I took your advice. Restructured it to a database, which was also helpful in removing duplicates automatically. Here's what I ended up with:

Code:

$shipsearch_target = %params
$test = %db(@ship_db,$shipsearch_target)

#PRINT
#PRINT %ansi(white)Database information:

#IF ($test) {

  #FORALL @ship_db {
 
    #IF (%upper(%i.name) = %upper($shipsearch_target)) {
     
      #SHOW %ansi(white)%format("&s : &s : &s : &s : &s : &s", %i.name, %i.owner, %i.type, %i.planet, %i.dock, %i.date)
     
    }
  }
} {

  ls $shipsearch_target
 
}

#PRINT
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