|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Mon Mar 06, 2023 2:36 am
OK, so I can't seem to handle a simple IF statement |
I am foraying into the region of writing some more complicated triggers than "If the mud says I can't move, then delete the direction from the que and don't try to move."
I am trying to grab use gmcp info to help me with mapping, finding areas (zones), terrain types, etc. I am starting by trying to make a trigger that captures the zone, compares it to a list of zones, and then adds it and notifies me that I have changed zones if I actually entered a new zone with the last move. Below is the trigger so far - as you can see it isn't very long, but I have already blasted my head against a wall, and made several changes to no avail.
Code: |
<trigger name="Environment check and update" type="GMCP" priority="400" id="40">
<pattern>Room.Info</pattern>
<value>$newarea=%gmcp.room.info.area
$oldarea=%gmcp.olddata.area
#SAY "1" $newarea "2" $oldarea
#ADDITEM Areas $newarea
//#IF ($newarea != $oldarea){#SAY "New area entered"}{}
//#IF (%ismember($newarea,@Areas)) {}{#SAY "A new area has been found"}
</value>
|
The first issue is that #ADDITEM is not supposed to create duplicate entries, but does (@Areas will add the zone name every time the trigger fires, even on multiple looks in the same room). I presume this is just an error in the documentation, so I tried adding some comparisons. But each of the following IF statements will cause the trigger to not compile. The first one I just added to see if I could get a simple IF statement to work, but for some reason I can't. I am just comparing the two temporary variables, but that fails as well, so I guess the script isn't even evaluating how badly I'm screwing up the %ismember syntax.
Could someone put me out of my misery?
Mike |
|
Last edited by mikeC130 on Mon Mar 06, 2023 4:35 am; edited 1 time in total |
|
|
|
chaossdragon Apprentice
Joined: 09 Apr 2008 Posts: 168
|
Posted: Mon Mar 06, 2023 4:19 am |
Start with each line and do a #SHOW so your first line $newarea=%gmcp.Room.info.area test with #SHOW %gmcp.Room.info.area if this does work then you can move to the next line. should help figure out where it's derping out.
|
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Mon Mar 06, 2023 4:32 am |
The gmcp variable is being captured correctly and transferred to the temp variables- the #SAY command spits out the correct values for the current and previously entered room. It is just everything after that where I run into trouble. For some reason I am missing the correct syntax on the #IF statements and just can’t find what it is.
Mike |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Mon Mar 06, 2023 9:31 pm |
You need a space between one closing bracket/parentheses and the next opening bracket.
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Mon Mar 06, 2023 10:01 pm |
Yes, just found that out...
Formatting will be the death of me, and proofreading your own code sucks. I once spent five days in college going over a simple 30 line assembly program with no luck only to have a TA look at it for 5 seconds and then give me a rather glib "You used JUMP instead of JMP in that second to last line of the program..." In my own defense, in that case the assembler didn't even throw an error, it just threw a bunch of meaningless machine code into the card that I was trying to interface to a keyboard matrix (or something like that - it's been 30 years).
Thanks for the help.
Mike
At least I can now get both IF statements to work. Also, the documentation for #ADDITEM should be changed to indicate that it WILL add duplicate items to a stringlist. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Mon Mar 06, 2023 10:57 pm |
#ADDITEM does not add duplicates, but %additem does.
Might be the difference of a trailing space if #ADDITEM seems to make a duplicate. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Tue Mar 07, 2023 2:52 am |
Didn't use the function, only the command, and using the $newarea temp variable pulled directly from the gmcp data on repeated looks without moving I ended up with about 10 copies of the area name. I did have the settings editor open, viewing/editing either the trigger or the variable - I wonder if it could have affected the ability of the program to detect the fact that the entries were duplicated? In any case, with the formatting of the if statement working, I can check it before trying to add it, or do more testing to see what was happening.
|
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Tue Mar 07, 2023 8:24 pm |
OK, I can confirm that, for some reason, the #ADDITEM command does indeed add duplicates for me.
Continuing on and adding to the trigger I have been working on, here is the trigger:
Code: |
<trigger name="Environment check and update" type="GMCP" priority="400" id="40">
<pattern>Room.Info</pattern>
<value>$newarea=%gmcp.room.info.area
#IF (!%ismember($newarea,@Areas)) {#SAY "A new area has been found"}
#ADDITEM Areas $newarea
$environment = %gmcp.room.info.environment
Detail = %gmcp.room.info.details
#ADDITEM Environments $environment
#ADDITEM RoomDetails @Detail
#IF (%ismember("shop",@detail)) {#beep}</value>
<notes>adds additional entry to stringlist for RoomDetails and Environments for every time trigger fires - duplicate entries are made even upon multiple looks in same room</notes>
</trigger>
|
The trigger will fire every time I receive the Room.info message, which occurs when entering a room or doing a look. Every time the trigger fires, the variables Area, RoomDetails, and Environments get a new entry. If I delete those three variables and then do 3 looks, each will have 3 entries, one for each look, and those entries are identical. The program is probably still ticked that I left that space out between brackets in the first post.
I saved the Environments variable to xml after doing this. All 3 entries are identical, and they were created using the #ADDITEM command in the trigger.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<var name="Environments" type="StringList">
<value>Urban|Urban|Urban</value>
<json>["Urban","Urban","Urban"]</json>
</var>
</cmud>
|
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Thu Mar 09, 2023 6:40 pm |
Very odd behavior. as the #HELP file explicitly states it won't do that.
Try using %trim on the value to trim away any whitespace padding.
If that doesn't work, suppose it's possibly a corruption issue. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
mikeC130 Apprentice
Joined: 03 Jul 2006 Posts: 110
|
Posted: Sat Mar 18, 2023 6:13 pm |
Thought I'd come back and add a conclusion to this thread, in case someone sees it later and wonders what is going on.
As covered in another thread, the issue with the #ADDITEM command turned out to be a variable type issue. When adding a variable of a type that is NOT a string, the variable will be added but the built in process that checks for duplication will fail. This specifically includes a stringlist, even if it has only a single entry. A stringlist compared to a string will show as unique, but when added, will become a string, which will then not be matched against the next time that same stringlist is added (wash, rinse, repeat). In this case a single entry stringlist was created because it came in a gmcp packet that identified it as a stringlist - entries enclosed in square brackets are interpreted as stringlists regardless of how many elements are included, and entries in curly brackets {} become database variables.
Mike |
|
|
|
|
|