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


Joined: 19 May 2016
Posts: 9

PostPosted: Fri May 20, 2016 5:30 pm   

DB var with room names as key, list of zones as value
 
This script seems to work, but also throws a strange parsing error about painting to a canvas OR access violation on the roomzonelist variable.

Is there a better way to do this?

Code:
#loop %numrooms {
  #if (!@roomzonelist.%ROOMNAME(%i)) {
    #addkey {roomzonelist} %ROOMNAME(%i) %ZONENAME(%ROOMZONE(%i))
  } {
  $list=@roomzonelist.%ROOMNAME(%i)
  #if (!%ismember(%ZONENAME(%ROOMZONE(%i),$list))) {
    #additem $list %ZONENAME(%ROOMZONE(%i))
    #addkey {roomzonelist} %ROOMNAME(%i) $list}
  }
}
Reply with quote
shalimar
GURU


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

PostPosted: Fri May 20, 2016 8:43 pm   
 
You could use #MAPQUERY to perform a SQL search on the map database, if you are familiar with that.

Also, %zonename and %roomname need to be lowercase to evaluate out properly, unless I am mistaken.
_________________
Discord: Shalimarwildcat
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri May 20, 2016 9:11 pm   
 
I have a general distrust of using the dot notation when there is a complex item as in:
@roomzonelist.%ROOMNAME(%i)
My preference, as it will always produce a good result, would be:
%db(@roomzonelist,%ROOMNAME(%i))
But you can also use something like this to help ensure the correct result:
@{roomzonelist.%ROOMNAME(%i)}
Given that %roomname will have complex results I would go even further:
@{roomzonelist.{%ROOMNAME(%i)}}
Again, I think using the %db function is best.

Your #LOOP is running over the range 1 to %numrooms. If a particular value does not exist, for example you deleted a room, then all the various %roomXXXX functions will fail on that number. I am not entirely sure what you are doing so I can't suggest a solution.

Your indentation pattern is not consistent. It should not cause an problems in the script you provided, but it can be confusing for a human. The #SWITCH command is only command where CMud gets very picky about indentation/format.

In general parameters that can be multiple words should be encapsulated with braces. Nothing in your script would be an issue, but having the habit of using best practices can save hours of trying to find a bug when you do write something that might be an issue.
Bad: #addkey {roomzonelist} %ROOMNAME(%i) %ZONENAME(%ROOMZONE(%i))
Good: #addkey roomzonelist {%ROOMNAME(%i)} {%ZONENAME(%ROOMZONE(%i))}
Great: #addkey {roomzonelist} {%ROOMNAME(%i)} {%ZONENAME(%ROOMZONE(%i))}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Saros
Newbie


Joined: 19 May 2016
Posts: 9

PostPosted: Sat May 21, 2016 8:14 pm   
 
Thanks for your input! With your help, I came up with the following..

Sorry about my indentation pattern!

Code:
#loop 9811 { //9811 being the greatest room number currently used by the mapper
  #if (%roomname(%i)!=%null) {                  //skip rooms with null room names
    #if (%zonename(%roomzone(%i))!=%null) {     //skip rooms with null zone names
      #if (!@roomzonelist.%roomname( %i)) {#addkey {roomzonelist} %roomname( %i) %zonename( %roomzone( %i))} {
        $list=@roomzonelist.%roomname( %i)
          #if (!%ismember( %zonename( %roomzone( %i), $list))) {
            #additem $list %zonename( %roomzone( %i))
            #addkey {roomzonelist} %roomname( %i) $list
          }
      }
    }
  }
}


Why? Not everyone uses the mapper, I can share this variable and provide them with similar lookup functionality. #Kludge
Reply with quote
shalimar
GURU


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

PostPosted: Sat May 21, 2016 8:44 pm   
 
Code:
#LOOP %numrooms {
  $name=%roomname(%mapvnum(%i))
  $zone=%zonename(%mapvnum(%i))
  #IF (($name!=%null)&&($zone!=%null)) {
    $zone=%additem(%delitem(%db(@roomListZone, $name), $zone), $zone)
    #ADDKEY roomListZone $name $zone
    }
  }


%delitem inside the %additem to ensure no duplicates.
_________________
Discord: Shalimarwildcat
Reply with quote
Saros
Newbie


Joined: 19 May 2016
Posts: 9

PostPosted: Mon May 23, 2016 3:54 pm   
 
Slick! Thanks again.
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