Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Fri Oct 29, 2004 1:33 am   

Upgrading a scipt, need advice
 
I've got an alias to store and access coordinates that I made using parts of a script nexela had made, and the list of coordinates I've got now is quite long, 44+ entries now... and I've been pondering a way to organize the output I get when I get a list of coordinates... I want to categorize the locations based upon what they are, i.e. a store, a job opportunity, a bar, et cetera, and I've been thinking on ways to do this, and all I've come up with so far is storing each category in a different variable, for reference, this is the alias, it's called grid...

#IF (%iskey( @coords, %lower( "%1"))) {
~grid add %1 %db( @coords, %lower( "%1"))
~grid %1
~grid del %1
} {
#IF (%null( "%1")) {grid list}
#IF ("%1"="store") {
#ADDKEY coords {%lower( "%2")} {"%3" "%4"}
#SAY %proper( "%2") Stored
}
#IF ("%1"="delete") {
#DELKEY coords %lower( "%2")
#SAY %proper( "%2") Erased
}
#IF ("%1"="list") {
#SHOW @empty
#SHOW ~#~ ~ ~ ~ Stored Coordinates ~ ~ ~ ~#
#LOOPDB @coords {#SAY %if( %mod( %iskey( @coords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW %numkeys( @coords) coordinates stored
#CR
}
#IF ("%1"="add") {
#IF (%iskey( @coords, %2)) {
#SHOW @empty
#SAY That destination already exists.
#CR
} {
~grid add %2
~grid
}
}
}

While I'm on the topic of organization, I was wondering if it's possible with loopdb to somehow alphabetize the list it outputs...

Bck on topic, the separate variables for each category wouldn't be hard, I think all I'd need to do is modify the if statements in the above alias to use %iskey check each of the variables, instead of only the current one, coords. I think the pipe is OR, so instead of having #IF (%iskey( @coords, %2)), I'd have it as either #IF (%iskey( @stores OR @jobs OR @etc, %2)) if it's somehow possible to do it that way, or else I'd have it as #IF (((%iskey(@stores...)) OR ((%iskey(@jobs...)) OR (%iskey(@etc...)))

Let me know what you think, if there's an easier way, or if what I'm thinking will work fine

Also, to conserve space and keep only one new topic started, I was wondering if it's possible to do two other unrelated things... one, have a variable and do something like... say Hi, my name is Ralph and my number is @number, and have it replace @number with the contents of the variable, and similarly have say Hi, Bob's number is @list.bob and have it replace list.bob with the value for the key bob in a db variable
Reply with quote
misterbalrog
Apprentice


Joined: 26 Oct 2004
Posts: 108

PostPosted: Fri Oct 29, 2004 9:47 am   
 
would'nt %sort work out for you?
Reply with quote
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Fri Oct 29, 2004 9:24 pm   
 
Hmm, no, sort is only for string lists and the like, not a DB variable, I tried, but thank you

Also... I was wondering if it were possible to modify the "store" section of the above alias to accept more than one word... meaning... grid store One Two Three Et cetera -23234 2342342... If there's a way to make it recognize that all of the text after store goes into the key, and the numbers go into the value... and then have a way to grid <abbreviated destination> like... if I had a coordinate stored to Gun Shop, then just grid gun, and have it go to the Gun Shop coordinate... Whew, I know I'm asking a lot of stuff here, but mainly I just want to know if it's possible and the best way to accomplish them, nothing too serious
Reply with quote
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Sat Oct 30, 2004 1:40 am   
 
Okay, the question above still stands, but I've started converting the alias to use multiple variables to store the coordinates so I can organize them, but I was wondering if there is a way to give a list of variables, and a key you're searchign for, and have it return the name of the variable it was in... i.e %searchvars("findme",@db1,@db2,@db3) and have it give back @db3 since that's where the key findme was found... here's the problem...

#IF ((%iskey( @StoreCoords, %lower( %3))) | (%iskey( @JohnsonCoords, %lower( %3))) | (%iskey( @BarCoords, %lower( %3))) | (%iskey( @EtcCoords, %lower( %3)))) {
~grid add %1 %db( @coords, %lower( "%1")) ****
~grid %1
~grid del %1
}

I have the if set up to check all of the coord variables, but when I want it to execute the commands, I need %db function in the line with the four asterisks by it to call from the proper list... i.e. I have Guns stored in the StoreCoords variable, and I type grid guns, it runs through and checks all four of the Coord lists and finds it in StoreCoords, so I need it to ~grid add %1 %db( @StoreCoords, %lower( "%1")), but if I want to go to say, Bob the johnson, then I'd need it to ~grid add %1 %db( @JohnsonCoords, %lower( "%1")), any help here?

I just realized that I can do an %iskey check for each record and have it execute the commands accordingly, I'll do it that way, but for future reference is there a better way?
Reply with quote
rtatum
Novice


Joined: 19 Sep 2004
Posts: 45
Location: Houston

PostPosted: Sat Oct 30, 2004 4:25 am   
 
For those that are interested, or for those who see blatant errors and whatnot, here is the finished version of the updated script, comments are welcome, and if you see where I can improve, let me know:

alias: grid
#IF ((%iskey( @StoreCoords, %lower( %1))) | (%iskey( @JohnsonCoords, %lower( %1))) | (%iskey( @BarCoords, %lower( %1))) | (%iskey( @EtcCoords, %lower( %1))) | (%iskey( @ApartmentCoords, %lower( %1))) | (%iskey( @TownCoords, %lower( %1)))) {
#IF (%iskey( @StoreCoords, %lower( %1))) {~grid add %1 %db( @StoreCoords, %lower( "%1"))}
#IF (%iskey( @JohnsonCoords, %lower( %1))) {~grid add %1 %db( @JohnsonCoords, %lower( "%1"))}
#IF (%iskey( @BarCoords, %lower( %1))) {~grid add %1 %db( @BarCoords, %lower( "%1"))}
#IF (%iskey( @EtcCoords, %lower( %1))) {~grid add %1 %db( @EtcCoords, %lower( "%1"))}
#IF (%iskey( @ApartmentCoords, %lower( %1))) {~grid add %1 %db( @ApartmentCoords, %lower( "%1"))}
#IF (%iskey( @TownCoords, %lower( %1))) {~grid add %1 %db( @TownCoords, %lower( "%1"))}
#IF (%iskey( @CorpCoords, %lower( %1))) {~grid add %1 %db( @CorpCoords, %lower( "%1"))}
~grid %1
~grid del %1
} {
#IF (%null( "%1")) {grid list}
#IF (("%1"="store") & ((%lower( "%2")=storecoords) | (%lower( "%2")=johnsoncoords) | (%lower( "%2")=barcoords) | (%lower( "%2")=etccoords) | (%lower( "%2")=apartmentcoords)) | (%lower( "%2")=towncoords) | (%lower( "%2")=corpcoords)) {
#ADDKEY %2 {%lower( "%3")} {"%4" "%5"}
#SAY %proper( "%3") Stored
}
#IF (("%1"="delete") & ((%lower( "%2")=storecoords) | (%lower( "%2")=johnsoncoords) | (%lower( "%2")=barcoords) | (%lower( "%2")=corpcoords) | (%lower( "%2")=etccoords) | (%lower( "%2")=apartmentcoords) | (%lower( "%2")=towncoords))) {
#DELKEY %2 %lower( "%3")
#SAY %proper( "%3") Erased
}
#IF (("%1"="list") & (%null( "%2"))) {
#SHOW @empty
#SHOW ----------Johnsons----------
#LOOPDB @JohnsonCoords {#SAY %if( %mod( %iskey( @JohnsonCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW ------------Bars------------
#LOOPDB @BarCoords {#SAY %if( %mod( %iskey( @BarCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW -----------Stores-----------
#LOOPDB @StoreCoords {#SAY %if( %mod( %iskey( @StoreCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW --------Corporations--------
#LOOPDB @CorpCoords {#SAY %if( %mod( %iskey( @CorpCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW -----------Cities-----------
#LOOPDB @TownCoords {#SAY %if( %mod( %iskey( @TownCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW ---------Apartments---------
#LOOPDB @ApartmentCoords {#SAY %if( %mod( %iskey( @ApartmentCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#SHOW -----------Others-----------
#LOOPDB @EtcCoords {#SAY %if( %mod( %iskey( @EtcCoords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#CR
}
#IF ("%1"="add") {
#IF ((%iskey( @StoreCoords, %lower( %3))) | (%iskey( @JohnsonCoords, %lower( %3))) | (%iskey( @BarCoords, %lower( %3))) | (%iskey( @EtcCoords, %lower( %3))) | (%iskey( @ApartmentCoords, %lower( %3))) | (%iskey( @TownCoords, %lower( %3)))) {
#SHOW @empty
#SAY That destination already exists.
#CR
} {
CurrentCategory=%2
~grid add %3
~grid
}
}
}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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