Llohr Apprentice
Joined: 17 May 2005 Posts: 108
|
Posted: Sun Feb 23, 2014 12:02 am
#additem vs %additem, and %min issues |
According to documentation, #additem will not allow you to add duplicate items to a string list, while %addkey will. The trouble I am having is that both seem to allow for duplicates. For background, I'm writing a script that searches out specific targets when I use the "scan" command in-game. That command might give me an output like this:
Right here you see:
- Llohr
- a citizen
1 east from here you see:
- the Proprietor
- an excited child
- a harrassed parent
1 west from here you see:
- the Candlestick Maker
I have one trigger that records the direction and the number of steps, another that records the position in the room's stack, in case I want to interact without using a keyword, and another that holds a list of the locations of target mobs relative to me, and their positions in the stack.
That third trigger's value looks like this:
Code: |
#if (@Scanning.%char) {#additem %expand(//%char/Scan/TargetList,1).%expand(@TargetPosition.Steps,1) @TargetPosition.Direction
#if (%rightback(@TargetList.%expand(@TargetPosition.Steps,1),1) != {[0-9]}) {#var %expand(//%char/Scan/Targetlist,1).%expand(@TargetPosition.Steps,1) %additem(@TargetPosition.Stack,@TargetList.%expand(@TargetPosition.Steps,1))}} |
The idea is, I use #additem to record the direction of the mob in a stringlist, with a key equaling the number of steps away the mob is. I used addkey here, because I did not want to record that there are multiple matching mobs in a single room. Then I check to ensure that the last recorded item in the stringlist is not a number (i.e., it's a direction), and if it is not a number, I record the position in the stack. I want to be able to duplicate the position in stack string, because I might have a mob one north that's the second mob in the room, and a mob 1 east that is the second mob in the room, so they'll both be in the stringlist contained in @TargetList.1, but the string immediately preceding them in the list will be different. I get a stringlist like this: @TargetList.1 = {n|2|e|2}.
That way, when I walk to the first mob, I delete the first two items in the stringlist upon reaching the target room, and if I find that a fight is already in progress, I retrace my steps to the starting position, and check the variable for the next available mob. If I see two targets in the same room, I currently get a stringlist like {n|1|n|2}, wherein deleting the first two items and retracing my steps just sends me back to the same room. Is this the correct behavior?
Do I need to do an if %ismember check to remove duplicate directions from a given string list?
My other question regards %min. Reading the forums here, I found a post from Zugg explaining that the %min function can be used to return the lowest value contained in a database variable or string list, but a simple "#show %min(@variable.key)" returns the complete string list of every key in that variable. Is there an alternative? I'd like to set up the scan script to automatically go to the closest available target, and can do that with #switch, but I'd like to simplify it a bit more if I can. Switches are ugly when cMud doesn't recognize them if you put each (condition) {action} on a new line. |
|