|
Xerakon Apprentice
Joined: 10 May 2011 Posts: 111
|
Posted: Thu Apr 27, 2017 2:03 am
IF - matching entry to string list |
Hello. I have a script here that cleans up a database and then places everything into a local variable list while it works, then replaces the original database. It has worked faithfully for several years, but there are now some entries which will never be needed in the finalized database. What I have done is created a variable stringlist (@research_smuggling) containing the names of the items that I do not want to appear in the final database. What I have tried to do is add a simple #IF statement into the cleaner script that doesn't appear to be filtering out. Is this a syntax issue, or is it not possible to remove a variable based off of a string list of matching variables?
Code: |
#LOOPDB @research_database {research_database.%key = %replace(%val,"%","|")}
$res_list = {}
$res_skill = {}
$res_value = {}
#LOOPDB @research_database {
#FORALL %val {
#SWITCH (%rightback(%i,2) =~ " ") {
$res_skill = %trim(%leftback(%i,1))
$res_value = %trim(%rightback(%i,1))
} (%rightback(%i,3) =~ " ") {
$res_skill = %trim(%leftback(%i,2))
$res_value = %trim(%rightback(%i,2))
} {
$res_skill = %trim(%leftback(%i,3))
$res_value = %trim(%rightback(%i,3))
}
// Attempted #IF != statement.
#IF ($res_list != @research_smuggling) {
#ADDKEY $res_list $res_skill $res_value
}
}
}
research_database = $res_list
|
Thanks! |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Thu Apr 27, 2017 5:00 am |
Presumably you don't want to compare an item to the list itself - you just want to check if the list contains that item? You can use the %ismember function for that.
|
|
|
|
Xerakon Apprentice
Joined: 10 May 2011 Posts: 111
|
Posted: Thu Apr 27, 2017 8:24 pm |
Thank you, Daern. That worked a charm.
My next request along the same lines comes in the form of a database record search. Here is an example of a nested #IF chain I have implemented:
Code: |
#IF (%ismember($res_skill,@research_smuggling)) {} {
#IF (($res_value >= 15)&(%ismember($res_skill,@research_sciences))) {} {
#IF (($res_skill = "shipdodge")&($res_value >= 30)) {} {
#IF (($res_skill = "slice")&($res_value >= 15)) {} {
#IF (($res_skill = "secure")&($res_value >= 15)) {} {
#IF (($res_skill = "buildship")&($res_value >= 45)) {} {
#IF (($res_skill = "ponder")&($res_value >= 20)) {} {
#IF (($res_skill = "flurry")&($res_value >= 15)) {} {
#ADDKEY $res_list $res_skill $res_value
}
}
}
}
}
}
}
} |
I have a couple of string lists that I can use to filter out the bulk of the skills necessary, but I'm wondering if I can build a database that continues the $res_skill and $res_value and somehow ensure that the skill being checked contains >= the matching value.
Thanks! |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Fri Apr 28, 2017 5:57 am |
Might I recommend the #SWITCH command?
Much more legible than nested #IFs if nothing else. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Xerakon Apprentice
Joined: 10 May 2011 Posts: 111
|
Posted: Fri Apr 28, 2017 11:57 pm |
Hey shalimar,
Thanks for the tip! Would you mind assisting me with how that might look like in this scenario? The #SWITCH in the above code was down by someone that assisted me before. From my understanding, #SWITCH is used to match one variable's different states. In this case, there are atleast 2 global variables and 2 different local variables.
Thanks! |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Sat Apr 29, 2017 3:53 am |
Oh, so i see, looks more involved then I thought at first
Code: |
#SWITCH ($res_skill)
(shipdodge) {#IF ($res_value>=30) {stuff}}
(slice) {#IF ($res_value>=15) {stuff}}
{default action} |
Something like this I suppose.
You could even have nested #SWITCHes to make it easy to cover every possible combination of values.
No need to even check the %ismembers this way, as you are specifying all possible outcomes in the code itself.
It won't matter if its a value you haven't accounted for in the #SWITCH. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Daern Sorcerer
Joined: 15 Apr 2011 Posts: 809
|
Posted: Sun Apr 30, 2017 5:30 am |
Alternatively, you could create a database variable with the required values for each skill and look them up in that.
Code: |
$required_values = {shipdodge=30|slice=15|secure=15| .... }
#IF (!%iskey($required_values, $res_skill) OR $res_value < %db($required_values, $res_skill)) {
#ADDKEY $res_list $res_skill $res_value
} |
|
|
|
|
|
|