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
peewee
Wanderer


Joined: 22 Oct 2000
Posts: 90
Location: Sweden

PostPosted: Sun Sep 08, 2002 10:24 pm   

Converting a path to string list
 
Greetings and salutations, fellow zMUD users!
I was looking for a way to convert the steps in a path to an array or string list variable... Wouldst that be possible, I wonder? Without having to create the variable manually and then enter the steps manually, I mean...

Peace, love and lots of coca cola!


"May the Force be with you"
[url]peeweesweden@bredband.net[/url]
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Sep 09, 2002 12:18 am   
 
quote:

Greetings and salutations, fellow zMUD users!
I was looking for a way to convert the steps in a path to an array or string list variable... Wouldst that be possible, I wonder? Without having to create the variable manually and then enter the steps manually, I mean...

Peace, love and lots of coca cola!


"May the Force be with you"
[url]peeweesweden@bredband.net[/url]



Yep, that's possible. All you'd need to do is use the %right(), %rightback(), %left(), %leftback() functions to pull out each individual number or letter and determine which one it was. If it's a letter, you must access another stringlist to determine what the direction was supposed to be (so you can handle user-defined directions). If it's a number, you simply loop that many times with the last direction.

Really, it's not that hard to do, though it might be tedious.

li'l shmoe of Dragon's Gate MUD
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Sep 09, 2002 2:29 am   
 
Taken from my own cache of scripts:

Alias: ConvertToPath


#SHOW Setting Path
CurrentPath=""
CurrentPathPointer=1
TempPath=%replace(@TempPath,";","|")
TempPath=%replace(@TempPath,"||","|")
#LOOP %numitems(@TempPath) {
TempPathPointer=%i
#IF %begins(%item(@TempPath,@TempPathPointer),".") {
#LOOP 2,%len(%item(@TempPath,@TempPathPointer)) {
CurrentPath=%concat(@CurrentPath,@DirCommands(%copy(%item(@TempPath,@TempPathPointer),%i,1)),"|")
}
} {
CurrentPath=%concat(@CurrentPath,%item(@TempPath,@TempPathPointer),"|")
}
}

Function: DirCommands


%if("%1"="+",d,%if(%1=1,sw,%if(%1=2,s,%if(%1=3,se,%if(%1=4,w,%if(%1=6,e,%if(%1=7,nw,%if(%1=8,n,%if(%1=9,ne,%if("%1"="-",u,%1))))))))))


I use the numberpad characters to represent directions in my internal code because it saves me thinking of 2 seperate naming systems.

Also in the BetaForum on 7/31 I posted this solution for comparing the length of 2 paths, a portion of this script could be used to do what you want.

#CLASS {PathLength}
#ALIAS ExpandPath {TempCounter=40;#WHILE (@TempCounter) {#IF (%pos(@TempCounter,@TempExpandPath)) { TempExpandPath=%replace(@TempExpandPath,@TempCounter, %repeat(%copy(@TempExpandPath, %eval(%pos(@TempCounter, @TempExpandPath)+%len(@TempCounter)),1),%eval(@TempCounter-1)))};#ADD TempCounter -1}}
#ALIAS ComputePathLength {TempLen=0;#FORALL %replace(@TempExpandPath,";","|") { #IF (%left(%i,1)=".") {#ADD TempLen %eval(%len(%i)-1)} {#ADD TempLen 1}}}
#ALIAS AddLocation {#IF (%trigger(AutoMapper)) { #IF ("%1"!="") { #IF (%ismember("%1",@NamedLocations)=0) {#ADDITEM NamedLocations {"%1"};#ADDITEM NumberedLocations {%roomnum}} { #ECHO Location by "%1" name already exists.}} { #ECHO Must specify a name you wish to assign.}} { #ECHO AutoMapper must be active to use this command.}}
#VAR TempExpandPath {} {}
#VAR TempPath1 {} {}
#VAR TempPath2 {} {}
#VAR TempCounter {0} {0}
#VAR TempLen1 {0} {0}
#VAR TempLen2 {0} {0}
#VAR TempLen {0} {0}
#VAR BetweenLocations {} {}
#FU ButCapFu {%if(%numitems(@BetweenLocations)=2,%item(@BetweenLocations,1)%repeat(" ",%eval(31-%len(@BetweenLocations)))%item(@BetweenLocations,2),%item(@BetweenLocations,1))}
#VAR ButHighVal {0} {0}
#VAR ButLowVal {0} {0}
#VAR ButCurVal {0} {0}
#VAR NamedLocations {}
#VAR NumberedLocations {}
#BUTTON 1 {"@ButCapFu"} {#IF (%trigger(AutoMapper)) {#IF (%numitems(@BetweenLocations)=2) {TempLen1=%ismember(%item(@BetweenLocations,1),@NamedLocations);TempLen2=%ismember(%item(@BetweenLocations,2),@NamedLocations);#IF (@TempLen1&@TempLen2) {TempPath1=%walk(%item(@NumberedLocations,@TempLen1));TempPath2=%walk(%item(@NumberedLocations,@TempLen2));TempExpandPath=@TempPath1;ExpandPath;ComputePathLength;TempLen1=@TempLen;TempExpandPath=@TempPath2;ExpandPath;ComputePathLength;TempLen2=@TempLen;ButHighVal=%eval(@TempLen1+@TempLen2);ButLowVal=%eval(@ButHighVal/2);#IF (@TempLen1<@TempLen2) { ButCurVal=@TempLen1} { ButCurVal=%eval(@ButHighVal-@TempLen2)};#T+ CalculatedLength} { #IF (@TempLen1) { #ECHO You forgot to add %item(@BetweenLocations,2) to the list.} { #ECHO You forgot to add %item(@BetweenLocations,1) to the list.}}}} { #ECHO AutoMapper must be active to use this button.}} {} {} {%if(%trigger(CalculatedLength),@ButCurVal,0)} {} {} {} {} {} {} {} {} {32784} {} {Gauge||12|%if(%trigger(CalculatedLength),@ButHighVal,1000)|%if(%trigger(CalculatedLength),@ButLowVal,50)|7} {} "" {} {} {}
#CLASS {CalculatedLength} {disable}
#ALARM *20 {#T- CalculatedLength}
#CLASS 0
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