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
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: Mon Aug 27, 2007 11:03 am   

additem addnitem feature request
 
I posted this back in the zmud days, and got a very clever response whose code actually spanned many lines. After importing my code to cmud it says I have an infinite loop and variables left of the stack so I thought I'd make this a feature request:


can you add an extra component to %additem or add a new function addnitem (if the speed of additem is affected)

Syntax: %additem(s,list[,index])

if index is not provided it defaults to %numitems(list) + 1

if index is greater than %numitems(list) + 1 it just fills it with empty strings up to that item number.

list = ""

#SHOW %additem("text",@list,3)

would display:
"||text"
or something along those lines

the reason for asking for this is....
1)it's a useful feature I think many people can use
2)any attempt to code an additem results in lots of potentially error prone code.
3)"|" operations should be handled by the list and not by outside "user created" routines.

Yes I know I can recode my previous aliases but I thought they were long enough, and this is a feature that probably should be handled at a lower level, that I thought I'd request it.

EDIT: One reason it makes it difficult to do outside the list is if the individual entries contain lists as entries I think the list becomes something like:

"goblins|(henchmen|pirates)|ogres" so that item 2 is a list so if you add at 3 simply by searching for a | you will be off
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: Mon Aug 27, 2007 5:24 pm   
 
I guess since additem only adds if the string is unique this should probably be an #ADDITEM feature and not an %additem feature, or maybe just a different function altogether insertnitem or something along those lines. still though, access to a specific slot location in an add would be helpful.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Aug 27, 2007 5:35 pm   
 
This is more array and index specific functionality. You can take a look at the BETA 2.01 version that provides Lua support. Fang has a nice Lua tutorial here
_________________
Asati di tempari!
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Tue Aug 28, 2007 9:54 pm   
 
#alias {addnitem} {templist=%1;#loop %eval(%numitems(%1)-%3) {#var list %additem(%item(%1,%i))};#var list %additem %2;#loop %eval(%numitems(%1-%3)+2),%numitems(%1) {#var list %additem(%item(%1,%i)}}

not tested, shoudl work by 'addnitem @list item slot'

so 'addnitem @weapons halbeard 5'
Reply with quote
gmueller
Apprentice


Joined: 06 Apr 2004
Posts: 173

PostPosted: Tue Aug 28, 2007 11:50 pm   
 
I've had bad experiences with #LOOP, in zmud you'd have to wrap it with a #PRI and even then it would still be a little temperamental assuming it needed to be a fast operation. I had an alias that had two loop statements in it, and it would actually return from the alias, update screen information and then jump back into the alias after then reupdate screen information again...(and there was no io processing in the loop) yeah, I'd like to avoid a #LOOP... anyway, I think this should be a low level command, seeing that databases should have a "private" structure (though in this case it's well documented enough to make it public)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Wed Aug 29, 2007 1:26 am   
 
You can use a bit of regex magic and insert to produce an insert item. Just off the top of my head it would look something like this
#VAR insertitem "%if(%regex(%3,%repeat(~"[^|]*?\|~",%2),$InsertPrePart),%insert(%concat(%1,~"|~"),%3,$InsertPrePart),%concat(%3,%repeat(~"|~",%eval(%numitems(%3)-%2)),%1))"
The syntax is similar to %replaceitem, it is @insertitem(item,position,list)

I used quotes instead of the braces that would normally be used for a variable as a consideration for my poor memory not recalling how exactly the new function had gotten implemented in 2.01. If you are working with version 1.34 then use the #FUNCTION command instead of #VAR.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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