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


Joined: 03 Jul 2006
Posts: 108

PostPosted: Wed Mar 08, 2023 7:10 pm   

OK, so the program just hates me
 
I am still having problems with my script. The first issue is that, yes, #ADDITEM is DEFINITELY adding duplicate variables. The second problem is that I have a comparison which for some reason WILL NOT correctly check to see if the element is present, and while I'm sure there is some simple format issue here, I can't find it.
The first two #IF statements work correctly, in that the first correctly evaluates %ismember() and only announces a new area if that title is not present in the @Areas variable, and neither now create duplicate entries into their respective stringlist variables.

The THIRD #IF statement, on the other hand, refuses to acknowledge that the stringlist already has not one, not two, or even three, but umpteen dozen copies of the environment entry in it, and stubbornly keeps adding new ones, even though the #ADDITEM in theory will not do this. I have modified the statement with some #SAY commands to show what it sees as the values of both the value being entered and the stringlist before and after the #IF statement and #ADDITEM, which shows it adding multiple entries. I even uninstalled and reinstalled the program in case something became corrupted, though the package files with the triggers are the original.

I start out with all values blank - no previously captured variables), and run 3 look commands in the same room to execute the trigger. I have deleted the results of the look for space, but below I have the output of the trigger itself, and a single copy of the Room.info message which comes in each time.

Code:
Trigger:

<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
#IF (!%ismember($environment,@environments)) {#ADDITEM Environments $environment} //Add to environment list if not present
//show that roomdetails includes the detail AND still adds it.
#SAY "Comparing detail " $detail " to see if it is within the stringlist " @RoomDetails
#IF (!%ismember($detail,@RoomDetails)) {#SAY "It seems that it is NOT!  Adding via #ADDITEM Command.  Old value " @Roomdetails;
#ADDITEM RoomDetails $detail; #SAY "Modified value " @RoomDetails}  //Add to Room details list if new
#IF (%ismember("shop", $detail)) {#beep}  //Let me know if there is a shop here - I'll work on colors later5</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>

Code:

Room.Info
02:11:44.115p | <IAC><SB><201>Room.Info { "num": 8458, "name": "The empty eastern square", "desc": "A lack of life and luster characterized this portion of the eastern square, leaving behind only the weeds to thrive successfully, such as the ivy that clung to one of the broken statues. A few pieces of broken pottery can be heard cracking beneath your feet or seen reflecting the sun vaguely. Some patches of stone have been left unmarred by time and weather, allowing for a few choice spots to sit and contemplate the wide, empty area.", "area": "the ruins of Caanae", "environment": "Urban", "coords": "1,1,0,0", "map": "www.imperian.com/irex/maps/clientmap.php?map=1&building=0&level=0 8 7", "details": [ "outdoors" ], "background": "urban-outdoors", "linecolor": "#0a0a0a", "exits": { "e": 8541, "sw": 8453, "w": 8463, "nw": 8472, "in": 29412 } }<IAC><SE><IAC><SB><201>Room.Players [  ]<IAC><SE><IAC><SB><201>Char.Vitals { "hp": "2220", "maxhp": "2220", "mp": "2220", "maxmp": "2220", "nl": "30", "bal": "1", "eq": "1", "string": "H:2220/2220 M:2220/2220 NL:30/100 ", "charstats": [ "Level: 48  (30.46%)" ] }<IAC><SE>


And finally the output from the trigger running three successive looks.
Quote:

***************First Look********************
A new area has been found
Comparing detail outdoors to see if it is within the stringlist
It seems that it is NOT! Adding via #ADDITEM Command. Old value
Modified value outdoors

***************Second Look********************
Comparing detail outdoors to see if it is within the stringlist outdoors
It seems that it is NOT! Adding via #ADDITEM Command. Old value outdoors
Modified value outdoors|outdoors
The empty eastern square.

***************Third Look********************
Comparing detail outdoors to see if it is within the stringlist outdoors|outdoors
It seems that it is NOT! Adding via #ADDITEM Command. Old value outdoors|outdoors
Modified value outdoors|outdoors|outdoors


As you can see, the first time through, the trigger successfully notes that the new area value is not in the list of areas (because I deleted it), and calls it out as a new area. The area is then added to the @Areas stringlist. The environments check also goes well in that only one entry is added to the stringlist. However, the third IF fails to correctly identify the presence of the entry "outdoors" on the second and third look, and as noted indeeds succeeds in making a duplicate entry using the #ADDITEM command.

Mike
Reply with quote
shalimar
GURU


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

PostPosted: Thu Mar 09, 2023 7:29 pm   
 
Might simply be a corruption issue.

Export your settings to XML from the package editor.
Close the session/CMUD
Move/rename/delete the .pkg file
A blank .pkg file will be created when you reopen the session.
Import from XML in the package editor.
_________________
Discord: Shalimarwildcat
Reply with quote
mikeC130
Apprentice


Joined: 03 Jul 2006
Posts: 108

PostPosted: Fri Mar 10, 2023 2:14 pm   
 
Issue persists across an export/import cycle. It also seems to be contagious, because I installed CMUD on another computer and typed in a new script which does the same thing. Interestingly, it also fails on checking that same entry from room.info.details, seeing every single "outdoors" as a unique value that is added again (perhaps there is something "malformed" about that variable coming from the MUD, though I can't see it in the debugger?). Of interest, when I simply type it into the command line, #ADDITEM does NOT add a duplicate (on either computer), so it appears only to appear when I write it in a script. It doesn't appear that I am typing it wrong, because it behaves differently between command line and script when I cut/paste the command between the two.

To be honest, I'm having flashbacks to my Fortran programming class in College - having some type of formatting error on a line would show up as a compiler error on another totally unrelated line, which might be before or after that line in the actual program.

Also, I know that it is a bit late to make a complaint about the way the commands are formatted, but WHY are the order of parameters reversed between %additem and #additem (and it seems inconsistent between various functions)? Did someone realize that I would eventually come along and decide ahead of time to just torture me? I think I'm going to have to type out a cheat sheet of all the functions and commands (though I'm currently using a total of approximately 3) so I don't have to pull up the support page every time.

Thanks for the help.

Mike
Reply with quote
mikeC130
Apprentice


Joined: 03 Jul 2006
Posts: 108

PostPosted: Sat Mar 11, 2023 3:24 am   
 
Just had a thought as to what MIGHT be an issue. The room.info.details packet does indeed come back as "non-standard," at least compared to the rest of the gmcp message. The data packet (I believe) represents that the variable is an array or stringlist. Note the following section of the gmcp packet including the "details" entry plus the next entry "background":

Code:

"details": [ "outdoors" ], "background": "urban-outdoors"

for the "details" portion of the message, the value includes brackets around the single value. This is the only packet that includes square brackets - the exits packet includes multiple entries, but uses {} to contain a set of "subpacket" pairs of entries and values. Is it possible that CMUD is treating the temporary value itself as a stringlist or array, and this is causing both failure of the %ismember comparison and allowing #ADDITEM to create a duplicate entry? Obviously it isn't failing to capture the value completely, as it does include the value of the entry and adds it to the list of entries. I recall that there were rooms that had two entries ("urban" and "outdoors" I believe), and #ADDITEM would indeed add both into the same line of the variable as essentially a stringlist inside the stringlist.

If this is indeed the case, any suggestions on the best way to handle it?

Mike

EDIT - Yep, that seems to be the issue. Creating detail as a regular rather than temporary value, it shows up as being of type stringlist. It seems that both %ismember and #ADDITEM will have *issues* when using a stringlist as the value to be checked/added rather than a string. So I guess I need to find a way to iterate through a stringlist and check/add each value separately, OR transform the stringlist into a simple string with any and all elements concatenated before checking if it is already in the list.
Reply with quote
shalimar
GURU


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

PostPosted: Sat Mar 11, 2023 1:45 pm   
 
try:

#FORALL $var {then the #IF #ADDITEM off of %i}
_________________
Discord: Shalimarwildcat
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