|
dacheeba Adept
Joined: 29 Oct 2001 Posts: 250
|
Posted: Tue May 21, 2002 2:54 pm
String Logic Problem |
Ok, need some help here.
Need to take a string variable such as:
#VAR @swdir {north|north|east|north|open down|down|north}
or
#VAR @swdir {north|west|west|south|up|enter portal|east|down}
Replace all standard exits(no northwests or southeast to worry about) with the letter begining the exit name(n,w,e,s,u,d). Then an occcurance of 2 or more directly following the same direction and compound them with a numerical digit(n|n=2n or d|d|d|d|d=5d).Anything not a standard exit needs to keep its position, but have a ';' before and after.If there are more standard exits after the non-standard ones, append 'run ' after the seperator for the non-standard exit.
The end product should look like:
run 2nen;open down;run dn
or
run n2wsu;enter portal;run ed
I can get as far as replacing the standard exits with thier first letter, but after that I'm at a loss.Thanks in advance for any help :) |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue May 21, 2002 5:45 pm |
Try the built-in commands first.
#VAR here {%roomnum()}
#MARK
#LOOP 1,%numitems(@swdir) {#MAP %item(@swdir,i)}
#PATH run
#TEL @here
LightBulb
Vague questions get vague answers |
|
|
|
dacheeba Adept
Joined: 29 Oct 2001 Posts: 250
|
Posted: Tue May 21, 2002 6:19 pm |
Hmm, the logic in that is close, but:
1. I need the run command assigned to the begining of the path and every instance where the path gets seperated by ';' for portals and doors...
2.#LOOP 1,%numitems(@swdir) {#MAP %item(@swdir,i)} doesn seem to add the doors or portals, only standard exits.
That is very close to what I want though. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue May 21, 2002 11:19 pm |
quote:
Ok, need some help here.
Need to take a string variable such as:
#VAR @swdir {north|north|east|north|open down|down|north}
or
#VAR @swdir {north|west|west|south|up|enter portal|east|down}
Replace all standard exits(no northwests or southeast to worry about) with the letter begining the exit name(n,w,e,s,u,d). Then an occcurance of 2 or more directly following the same direction and compound them with a numerical digit(n|n=2n or d|d|d|d|d=5d).Anything not a standard exit needs to keep its position, but have a ';' before and after.If there are more standard exits after the non-standard ones, append 'run ' after the seperator for the non-standard exit.
The end product should look like:
run 2nen;open down;run dn
or
run n2wsu;enter portal;run ed
I can get as far as replacing the standard exits with thier first letter, but after that I'm at a loss.Thanks in advance for any help :)
#alias FixSW {
#variable NonstandardCommands "enter|go|open|etc"
#variable SWsteps %numitems(%1)
#variable TempSW %1
#loop 1,%numitems(@NonstandardCommands) {
#while (@SWsteps > 0) {
#if (%begins(%i,%item(@TempSW,@SWsteps)) {
#NOOP this item is a nonstandard exit
%replaceitem(~;%item(@TempSW,@SWsteps)~;,@SWsteps,@TempSW)
} {#NOOP this item is a standard exit}
#add SWsteps -1
}
SWsteps = %numitems(%1)
}
#NOOP set @TempSW to your @swdir variable and delete (#unvar) the variables @TempSW and @SWsteps as they are no longer needed
}
All untested, but hopefully you get the idea of what it's doing.
li'l shmoe of Dragon's Gate MUD |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue May 21, 2002 11:39 pm |
Here ya go, only known flaw is it will not correctly set 200 consecutive norths as 200n, 199 would work, but the 200th would endup being recorded as 1100.
#CLASS {DirectionConverter}
#ALIAS ConvertDirs {#IF ("%1"="") { #ECHO Requires variable with source directions.} { #IF (%defined( "%1")=0) { #ECHO Source direction variable does not exist.} {TempDirCount=0;TempDirConvert="";ConvertedDirections="";#WHILE (@TempDirCount<%numitems( @%1)) {#ADD TempDirCount 1;#IF (%ismember( %item( @%1, @TempDirCount), @DirectionList)) { #IF (%char( %ascii( %item( @%1, @TempDirCount)))=%rightback( @TempDirConvert, 1)) {TempDirConvert=%concat( @TempDirCount, "|", @TempDirConvert);TempDirCount=%left( %rightback( @TempDirConvert, 3), 2);#IF (%isnumber( @TempDirCount)) {#ADD TempDirCount 1;TempDirConvert=%leftback( @TempDirConvert, 3)} {TempDirCount=%rightback( @TempDirCount, 1);#IF (%isnumber( @TempDirCount)) {#ADD TempDirCount 1;TempDirConvert=%leftback( @TempDirConvert, 2)} {TempDirCount=2;TempDirConvert=%leftback( @TempDirConvert, 1)}};TempDirConvert=%concat( @TempDirConvert, @TempDirCount, %char( %ascii( %item( @%1, @TempDirCount))));TempDirCount=%item( @TempDirConvert, 1);#DELNITEM TempDirConvert 1} { TempDirConvert=%concat( @TempDirConvert, %char( %ascii( %item( @%1, @TempDirCount))))}} {#IF (@TempDirConvert!="") {ConvertedDirections=%concat( @ConvertedDirections, "run ", @TempDirConvert, "|");TempDirConvert=""};ConvertedDirections=%concat( @ConvertedDirections, %item( @%1, @TempDirCount), "|")}};#IF (@TempDirConvert!="") { ConvertedDirections=%concat( @ConvertedDirections, "run ", @TempDirConvert)};#DELITEM ConvertedDirections "";ConvertedDirections=%replace( @ConvertedDirections, "|", ";")}}}
#VAR DirectionList {north|south|east|west|up|down}
#VAR TempDirConvert {}
#VAR TempDirCount {0}
#VAR ConvertedDirections {}
#CLASS 0 |
|
|
|
dacheeba Adept
Joined: 29 Oct 2001 Posts: 250
|
Posted: Wed May 22, 2002 2:21 am |
WOW, that must have taken you a while Vijilante! Well, I think this will get me on the right track, thanks a bunch guys :)
U r r0x0r,w00t :P |
|
|
|
dacheeba Adept
Joined: 29 Oct 2001 Posts: 250
|
Posted: Wed May 22, 2002 3:57 am |
Ok, the script does something wierd. When it converts:
#VAR swdir {north|open north|north|up|west|open west|west|west|west|down|down|down|down|down|open down|down|east|east|south|south|south|up|up|up|up}
The output is:
run n;open north;run nuw;open west;run 2ow2o2od;open down;run d2o2os2o2o
It changes all the multi dir commands to 'o', and beyond that, it puts them in pairs of 2, which is fine, as long as it sends the actual command
.Cant find the problem, there are no syntax errors that I can find(but thats one hell of an alias to comb thru :P)
Any idea why its changing them to 'o's? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed May 22, 2002 11:13 am |
Minor logic flaw. The section that does the counting of repeated directions stores TempDirCount so it can use for math. I was then using it refetch the direction from the orginal list before resetting it. Hence it was fetching open north and dropping that in as an o. So problem resolved.
#ALIAS ConvertDirs {#IF ("%1"="") { #ECHO Requires variable with source directions.} { #IF (%defined( "%1")=0) { #ECHO Source direction variable does not exist.} {TempDirCount=0;TempDirConvert="";ConvertedDirections="";#WHILE (@TempDirCount<%numitems( @%1)) {#ADD TempDirCount 1;#IF (%ismember( %item( @%1, @TempDirCount), @DirectionList)) { #IF (%char( %ascii( %item( @%1, @TempDirCount)))=%rightback( @TempDirConvert, 1)) {TempDirConvert=%concat( @TempDirCount, "|", @TempDirConvert);TempDirCount=%left( %rightback( @TempDirConvert, 3), 2);#IF (%isnumber( @TempDirCount)) {#ADD TempDirCount 1;TempDirConvert=%leftback( @TempDirConvert, 3)} {TempDirCount=%rightback( @TempDirCount, 1);#IF (%isnumber( @TempDirCount)) {#ADD TempDirCount 1;TempDirConvert=%leftback( @TempDirConvert, 2)} {TempDirCount=2;TempDirConvert=%leftback( @TempDirConvert, 1)}};TempDirConvert=%concat( @TempDirConvert, @TempDirCount);TempDirCount=%item( @TempDirConvert, 1);TempDirConvert=%concat( @TempDirConvert, %char( %ascii( %item( @%1, @TempDirCount))));#DELNITEM TempDirConvert 1} { TempDirConvert=%concat( @TempDirConvert, %char( %ascii( %item( @%1, @TempDirCount))))}} {#IF (@TempDirConvert!="") {ConvertedDirections=%concat( @ConvertedDirections, "run ", @TempDirConvert, "|");TempDirConvert=""};ConvertedDirections=%concat( @ConvertedDirections, %item( @%1, @TempDirCount), "|")}};#IF (@TempDirConvert!="") { ConvertedDirections=%concat( @ConvertedDirections, "run ", @TempDirConvert)};#DELITEM ConvertedDirections "";ConvertedDirections=%replace( @ConvertedDirections, "|", ";")}}} |
|
|
|
dacheeba Adept
Joined: 29 Oct 2001 Posts: 250
|
Posted: Wed May 22, 2002 1:41 pm |
Heh, this is why I hate large scripts, they are a pain to search though
Anyways, I tried and tried to fix this on my own, but it makes it harder for me, not having actually writen it my self.The problem now is @ConvertedDirections returns:
north;open north;north;up;west;open west;west;west;west;down;down;down;down;down;open down;down;east;east;south;south;south;up;up;up;up
I ran it though the debugger, so I could see it step by step, and near as I can tell it gets to:
#IF (@TempDirConvert!="") {ConvertedDirections=%concat(@ConvertedDirections, "run ", @TempDirConvert, "|") TempDirConvert=""} ConvertedDirections=%concat( @ConvertedDirections, %item(@%1,@TempDirCount), "|")
And evaluates it as true. I cant manage to find where it decides to make @TempDirConvert="" though. Any idea? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Wed May 22, 2002 10:48 pm |
I just tested it through again and it passed. The output your showing looks more like the DirectionList variable is missing. I did not include that in the updated post as the only thing needing updating was the misbehaving alias.
|
|
|
|
dacheeba Adept
Joined: 29 Oct 2001 Posts: 250
|
Posted: Wed May 22, 2002 11:46 pm |
*bonk self* yeah, for some reason it was set for 'Use Default' and the default field was null. Didnt even bother to check it. Works beautifully now. And I must say its suprisingly fast. I'm all good to gow now! :)
Thanks again. |
|
|
|
|
|
|
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
|
|