|
BoringCabbage Newbie
Joined: 01 Sep 2003 Posts: 6
|
Posted: Mon Feb 23, 2004 9:18 pm
Converting speedwalk character into direction |
Is there a predefined function to convert a speedwalk character (eg. h, j, k and l) into its actual direction (eg. nw, ne, sw and se)? I have written the following function to do this but I feel sure there must be a more elegant way to achieve it.
#FUNC muddir {%if( %item( %1, %2)="h", @muddir(%replaceitem( "nw", %2, %1),%eval(%2+1)), %if( %item( %1, %2)="j", @muddir(%replaceitem( "ne", %2, %1),%eval(%2+1)), %if( %item( %1, %2)="k", @muddir(%replaceitem( "sw", %2, %1),%eval(%2+1)), %if( %item( %1, %2)="l", @muddir(%replaceitem( "se", %2, %1),%eval(%2+1)), %if( %2<%numitems( %1), @muddir(%1,%eval(%2+1)), %1)))))}
Usage: #say @muddir(%roomexit(),1) |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Mon Feb 23, 2004 10:48 pm |
I'm not aware of any built-in function to convert but this should do:
#FUNC CharToDir {%case(%ismember("%1", "n|e|s|w|u|d|h|j|k|l"), "n", "e", "s", "w", "u", "d", "nw", "ne", "sw", "se")}
Usage:
#SAY @CharToDir("h")
Another way on might think to do it would be using %exec to execute it as a speedwalk path and capturing the result. However, that doesn't work when there is a door in the direction you want to translate and the door command gets inserted into the string. |
|
|
|
BoringCabbage Newbie
Joined: 01 Sep 2003 Posts: 6
|
Posted: Tue Feb 24, 2004 2:24 am |
That would only work with one parameter though. My function works with a string list as an input (eg. "j|k|e|d") and outputs a string list (eg. "ne|sw|e|d"). I'm just wondering if there is a simpler way of achieving this, but as you say there is no predefined function.
|
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Tue Feb 24, 2004 3:25 am |
Ah, your question seemed geared toward a single character
In any case, it's quite possible to use my previous function as a base for the rest:
#FUNC CharsToDirs {%exec("#FORALL ~"%1~" {@CharToDir(%i)}")}
Usage:
#SAY @CharsToDirs("j|k|e|d") |
|
|
|
BoringCabbage Newbie
Joined: 01 Sep 2003 Posts: 6
|
Posted: Tue Feb 24, 2004 3:55 am |
Yes that works, and a lot simpler than my effort, thank you
|
|
|
|
|
|
|
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
|
|