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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Tanuki
Novice


Joined: 06 Nov 2008
Posts: 38

PostPosted: Mon Nov 12, 2012 7:26 pm   

Stack Helper Functions
 
I just thought I would give back a little and save someone some time. If this belongs somewhere else let me know and I will move it.

This first Function will take a Sentence and return a Stack or List.
Example:
#Trigger { (*) }
#VAR MyStack @CreateStack(%1)

This will turn anything into "This|will|turn|anything|into" a list

Code:
<func name="CreateStack" id="10">
  <value>$Stack = %trim(%replace( $String, " ", "|"))
#Return $Stack</value>
  <arglist>$String</arglist>
</func>



The Second Function will reverse the list.
Example
#echo @ReverseStack(@MyStack)

Will return
"into|anything|turn|will|This"

Code:
<func name="ReverseStack" id="13">
  <value>#VAR ReversedStack ""
#VAR $Count %numitems($Stack)
#LOOP $Count,1 {#ADDITEM ReversedStack %item(@Stack,%i)}
#Return @ReversedStack</value>
  <arglist>$Stack</arglist>
</func>


Last edited by Tanuki on Mon Nov 12, 2012 10:07 pm; edited 1 time in total
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Mon Nov 12, 2012 9:48 pm   
 
Your first function actually already exists built-in - %list ;)
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Mon Nov 12, 2012 10:37 pm   
 
nevermind
_________________
Discord: Shalimarwildcat
Reply with quote
Tanuki
Novice


Joined: 06 Nov 2008
Posts: 38

PostPosted: Mon Nov 12, 2012 11:27 pm   
 
Good to know... I keep needing it and didn't want redundant code.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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