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


Joined: 12 Feb 2010
Posts: 2

PostPosted: Fri Feb 12, 2010 4:12 am   

%query problem with multiple arguments
 
I am having an issue with using %query to find multiple criteria. Easier to show the code...

Code:

#DBLOAD eq
$eqlocs = {light|finger|neck|body|head|legs|feet|hands|arms|shield|about|waist|wrist|wield|held|all}
$stats = {level|acapply|hp|mana|ss|sbr|spet|srod|dam|hit|armor|dex|con|sta|wis|int|str|move|ag|an|ae|am|ac|at|aw|bser|lng|dag|twoh|attack|avgdam|infmage|infcleric|infmelee}
#IF (%1 = "")
{
  #SHOW %ansi(bold,cyan)Syntax: dbcomp <eq location|all> <field1> <field2> <field3>
}
#IF %ismember(%1,$eqlocs) {}
{
  #SHOW dbcomp: %ansi(bold,red)Invalid eq location - Available locations are ~(%ansi(bold,white)$eqlocs%ansi(bold,red)~)
  #EXIT
}

#IF (%2 != "")
{
  #IF %ismember(%subchar(%2,"1234567890<>=!",""),$stats) {}
  {
    #SHOW dbcomp: %ansi(bold,red)Invalid stat name ~"%2~" - Available stats are ~(%ansi(bold,white)$stats%ansi(bold,red)~)
    #EXIT
  }
  $Temp = %query((&%2),%1)
  #SHOW %ansi(bold,white)%numitems($Temp) %ansi(bold,cyan)Items match your criteria:
  #FORALL $Temp
  {
    #DBGET %i
    showdbcomp
  }
}

#IF (%3 != "")
{
    #IF %ismember(%subchar(%3,"1234567890<>=!",""),$stats) {}
  {
    #SHOW dbcomp: %ansi(bold,red)Invalid stat name - Available stats are ~(%ansi(bold,white)$stats%ansi(bold,red)~)
    #EXIT
  }
  $Temp = %query(((&%2) && (&%3)),%1)
  #SHOW %ansi(bold,white)%numitems($Temp) %ansi(bold,cyan)Items match your criteria:
  #FORALL $Temp
  {
    #DBGET %i
    showdbcomp
  }
}

#IF (%4 != "")
{
  #IF %ismember(%subchar(%4,"1234567890<>=!",""),$stats) {}
  {
    #SHOW dbcomp: %ansi(bold,red)Invalid stat name - Available stats are ~(%ansi(bold,white)$stats%ansi(bold,red)~)
    #EXIT
  }
  $Temp = %query(((&%2) && (&%3) && (&%4)),%1)
  #SHOW %ansi(bold,white)%numitems($Temp) %ansi(bold,cyan)Items match your criteria:
  #FORALL $Temp
  {
    #DBGET %i
    showdbcomp
  }
}
#DBCLOSE eq


This works fine when i only use one argument.
But when I try to use multiple criteria all I get is EVERY record in the particular view I choose.
Example...
dbcomp wield hp>20
Shows all wield items that have hp>20

dbcomp wield hp>20 dam>2
Shows ALL wield items

The problem is in the syntax of query:
Code:

%query(((&hp>20) && (&dam>2)),wield)



Can anyone help me fix this?
Thanks
Reply with quote
Felnor
Newbie


Joined: 12 Feb 2010
Posts: 2

PostPosted: Fri Feb 12, 2010 7:39 pm   
 
Just to clerify:

This is the help file for query:

Quote:

Syntax: %query(expression,view)

returns a string list of record numbers for the records in the current view that match the query expression. If view is present, it is a string list whose first item is the name of the view to query, and optional second item is the database name.

Example:

#SHOW %query(((&Hit>2)&&(&Dam>2)),Weapons)

returns a list of records from the Weapons view where the Hit and Dam fields are both greater than 2.


But when I try to do the example above with using the &Hit and the &Dam criteria it will show ALL the records in the Weapons View.
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