Difference between revisions of "Dirrev.tf"

From AvatarWiki
Jump to navigation Jump to search
(Added a check if no argument was given to show the syntax and added some color to the result echo.)
(mutter at wiki whitespace stuff)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Bug reports, suggestions and/or diffs are appreciated, '''sulfar''' _AT_ ''inbox'' +DOT+ ''com''
 
 
 
Non issue: The script won't revert 3w200s, max supported is 99.
 
Non issue: The script won't revert 3w200s, max supported is 99.
  
 
<pre>
 
<pre>
/echo -aCyellow %% /dirrev <path>     Revert speedwalk path
+
/echo -aCyellow %% /dirrev <path>       Revert speedwalk path
  
 
/def -i dirrev = \
 
/def -i dirrev = \
    /if ({#}=0) \
+
        /if ({#}=0) \
        /echo -p %%% @{Cred}Syntax: /%{0} <path>@{n}%;\
+
                /echo -p %%% @{Cred}Syntax: /%{0} <path>@{n}%;\
    /else \
+
        /else \
        /set dir_str %1 %;\
+
                /let _dir_str %1 %;\
        /set dir_length $[strlen(dir_str)] %;\
+
                /let _length $[strlen(_dir_str)] %;\
        /set double_digit=0%;\
+
                /let _double_digit=0%;\
        /set dir_rev=%;\
+
                /set dirrev=%;\
        /for c 0 $[dir_length-1] \
+
                /for c 0 $[_length-1] \
            /set position $$[dir_length-c] %%;\
+
                        /let _position $$[_length-c] %%;\
            /set cur_char $$[substr(dir_str, position-1, 1)] %%;\
+
                        /let _cur_char $$[substr(_dir_str, _position-1, 1)] %%;\
            /set new_char %%{cur_char} %%;\
+
                        /if (_cur_char =~ "e") /let _new_char w %%;\
            /if (cur_char =~ "e") /set new_char w %%;/endif %%;\
+
                        /elseif (_cur_char =~ "s") /let _new_char n %%;\
            /if (cur_char =~ "s") /set new_char n %%;/endif %%;\
+
                        /elseif (_cur_char =~ "w") /let _new_char e %%;\
            /if (cur_char =~ "w") /set new_char e %%;/endif %%;\
+
                        /elseif (_cur_char =~ "n") /let _new_char s %%;\
            /if (cur_char =~ "n") /set new_char s %%;/endif %%;\
+
                        /elseif (_cur_char =~ "u") /let _new_char d %%;\
            /if (cur_char =~ "u") /set new_char d %%;/endif %%;\
+
                        /elseif (_cur_char =~ "d") /let _new_char u %%;\
            /if (cur_char =~ "d") /set new_char u %%;/endif %%;\
+
                        /else  /let _new_char %%{_cur_char} %%;\
            /if ((new_char =/ "[0-9]") & (!double_digit)) \
+
                        /endif %%;\
                /set dir_rev $$[strcat(substr(dir_rev, 0, c-1), new_char, substr(dir_rev, c-1, 1))] %%;\
+
                        /if ((_new_char =/ "[0-9]") & (!_double_digit)) \
                /if (substr(dir_str, position-2, 1) =/ "[0-9]") \
+
                                /set dirrev $$[strcat(substr(dirrev, 0, c-1), _new_char, substr(dirrev, c-1, 1))] %%;\
                    /set dir_rev $$[strcat(substr(dir_rev, 0, c-1), substr(dir_str, position-2, 1), substr(dir_rev, c-1, 2))] %%;\
+
                                /if (substr(_dir_str, _position-2, 1) =/ "[0-9]") \
                    /set double_digit 1 %%;\
+
                                        /set dirrev $$[strcat(substr(dirrev, 0, c-1), substr(_dir_str, _position-2, 1), substr(dirrev, c-1, 2))] %%;\
                /endif %%;\
+
                                        /let _double_digit 1 %%;\
            /elseif ( regmatch("[nsewud]", new_char) ) \
+
                                /endif %%;\
                /set dir_rev $$[strcat(dir_rev, new_char)] %%;\
+
                        /elseif ( regmatch("[nsewud]", _new_char) ) \
                /set double_digit 0 %%;\
+
                                /set dirrev $$[strcat(dirrev, _new_char)] %%;\
            /endif %;\
+
                                /let _double_digit 0 %%;\
        /echo -o %%% @{Cwhite}The reverse of @{Cgreen}%{dir_str} @{Cwhite}is @{Cgreen}%dir_rev@{n}%;\
+
                        /endif %;\
    /endif
+
                /echo -p %%% @{Cwhite}The reverse of @{Cgreen}%{_dir_str} @{Cwhite}is @{Cgreen}%dirrev@{n}%;\
 +
                /return "%dirrev"%;\
 +
        /endif
 
</pre>
 
</pre>
 
 
 
[[Category: TinyFugue Scripting]]
 
[[Category: TinyFugue Scripting]]

Latest revision as of 19:37, 9 November 2008

Non issue: The script won't revert 3w200s, max supported is 99.

/echo -aCyellow %% /dirrev <path>        Revert speedwalk path

/def -i dirrev = \
        /if ({#}=0) \
                /echo -p %%% @{Cred}Syntax: /%{0} <path>@{n}%;\
        /else \
                /let _dir_str %1 %;\
                /let _length $[strlen(_dir_str)] %;\
                /let _double_digit=0%;\
                /set dirrev=%;\
                /for c 0 $[_length-1] \
                        /let _position $$[_length-c] %%;\
                        /let _cur_char $$[substr(_dir_str, _position-1, 1)] %%;\
                        /if (_cur_char =~ "e") /let _new_char w %%;\
                        /elseif (_cur_char =~ "s") /let _new_char n %%;\
                        /elseif (_cur_char =~ "w") /let _new_char e %%;\
                        /elseif (_cur_char =~ "n") /let _new_char s %%;\
                        /elseif (_cur_char =~ "u") /let _new_char d %%;\
                        /elseif (_cur_char =~ "d") /let _new_char u %%;\
                        /else  /let _new_char %%{_cur_char} %%;\
                        /endif %%;\
                        /if ((_new_char =/ "[0-9]") & (!_double_digit)) \
                                /set dirrev $$[strcat(substr(dirrev, 0, c-1), _new_char, substr(dirrev, c-1, 1))] %%;\
                                /if (substr(_dir_str, _position-2, 1) =/ "[0-9]") \
                                        /set dirrev $$[strcat(substr(dirrev, 0, c-1), substr(_dir_str, _position-2, 1), substr(dirrev, c-1, 2))] %%;\
                                        /let _double_digit 1 %%;\
                                /endif %%;\
                        /elseif ( regmatch("[nsewud]", _new_char) ) \
                                /set dirrev $$[strcat(dirrev, _new_char)] %%;\
                                /let _double_digit 0 %%;\
                        /endif %;\
                /echo -p %%% @{Cwhite}The reverse of @{Cgreen}%{_dir_str} @{Cwhite}is @{Cgreen}%dirrev@{n}%;\
                /return "%dirrev"%;\
        /endif