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

 Related 
Contents
Lists
  #ADDITEM
  #DELITEM
  #DELNITEM
  #SORT
  %additem
  %countlist
  %delitem
  %delnitem
  %dups
  %expandlist
  %ismember
  %numitems
  %pop
  %push
  %replaceitem
  %sort
  Lists
Function Reference
  %abs
  %additem
  %addkey
  %alarm
  %alias
  %ansi
  %array
  %arrget
  %arrhigh
  %arrset
  %ascii
  %average
  %begins
  %bitand
  %bitnot
  %bitor
  %bitset
  %bitshift
  %bittest
  %bitxor
  %btncol
  %btnenable
  %btnimage
  %case
  %char
  %charcomment
  %charnotes
  %class
  %clip
  %color
  %colorname
  %colorsyntax
  %comactive
  %comcreate
  %comget
  %comset
  %concat
  %copy
  %count
  %countlist
  %crtonl
  %db
  %dbget
  %dbitems
  %dbkey
  %dbkeys
  %dblist
  %dbmax
  %dbmin
  %dbvalues
  %dde
  %ddeclose
  %ddemacro
  %ddeopen
  %ddepoke
  %defined
  %delete
  %delitem
  %delkey
  %delnitem
  %destroom
  %dice
  %diceavg
  %dicedev
  %dicemax
  %dicemin
  %doorname
  %dups
  %ends
  %eval
  %exec
  %exp
  %expand
  %expanddb
  %expandlist
  %filesize
  %find
  %float
  %format
  %getglobal
  %grep
  %gsl
  %handle
  %hexcolor
  %hexnum
  %hexstr
  %htmldecode
  %htmlencode
  %iconstate
  %if
  %insert
  %int
  %inwalk
  %isfloat
  %iskey
  %ismember
  %isnumber
  %isvalue
  %item
  %json
  %lastdir
  %left
  %leftback
  %len
  %line
  %list
  %literal
  %look
  %lower
  %mapfilter
  %maplocked
  %mapquery
  %mapvnum
  %match
  %max
  %mcp
  %min
  %mod
  %mss
  %nextdir
  %nltocr
  %norm
  %null
  %number
  %numbuttons
  %numitems
  %numkeys
  %numparam
  %numrec
  %numrooms
  %numwords
  %numzones
  %packages
  %param
  %params
  %parsemode
  %parsenumbers
  %pat
  %pathcompress
  %pathexpand
  %pathfrom
  %pathreverse
  %pick
  %pop
  %portal
  %portalenabled
  %pos
  %pref
  %priority
  %prompt
  %proper
  %push
  %query
  %quote
  %random
  %read
  %ref
  %regex
  %remove
  %repeat
  %replace
  %replaceitem
  %reversedir
  %rgb
  %right
  %rightback
  %roomcol
  %roomcom
  %roomcontents
  %roomcost
  %roomdesc
  %roomexit
  %roomflags
  %roomid
  %roomint
  %roomkey
  %roomkind
  %roomlink
  %roomload
  %roommode
  %roomname
  %roomnote
  %roomnum
  %roomportal
  %roomvnum
  %roomzone
  %round
  %section
  %setglobal
  %sort
  %sql
  %sqldb
  %sqrt
  %state
  %stdev
  %string
  %stripansi
  %stripq
  %subchar
  %subregex
  %sum
  %switch
  %threadid
  %threadname
  %time
  %trigger
  %trim
  %trimleft
  %trimright
  %upper
  %url
  %vartype
  %viewrec
  %walk
  %walkactive
  %walkconfirm
  %walkmode
  %walkroom
  %window
  %word
  %write
  %yesno
  %zonename
  %zonenum
  %zonevnum
Related Links:
  Lists
  %random
  %isvalue
%item [[cmud_%item]] 
item

Syntax: %item(list, n)

returns the nth item of the given stringlist.

As of version 2.06, this function can also be used to retrieve the nth value in a database variable (to return the nth key, see %dbkey).

Example:

#SHOW %item("Athos|Bertrand|Caesar",3)
displays: Caesar

 User comments 
Tech: Tue Aug 21, 2007 9:14 pm    

[Edit] Just adding some additional notes based on this thread.


The %item function does not autowrap like the #CASE does. If you have an n larger than the number of items in the list, the function will return a null value for those items.

This code snippet
Code:
 #loop 4 {#show %i : %item("one|two",%i)}

will output
Code:
1 : one
2 : two
3 :
4 :


If you do want it to do a "wrap-around" then a command similar to following should do the trick.
Code:
 #loop 4 {#show %i : %item("one|two",((%i-1) \ 2)+1)}
Arminas: Wed Aug 22, 2007 1:58 am    

Thank you Tech.
Quote:
#loop 4 {#show %i : %item("one|two",((%i-1) \ 2)+1)}

The blue 2 is the number of items in the list so.

For a list with more items you would want to make the appropriate change.
Quote:
#loop 4 {#show %i : %item("one|two|three",((%i-1) \ 3)+1)}

If you did not know how many items were in the list because you were using a variable list you could do this.
Quote:
#loop 4 {#show %i : %item(@list,((%i-1) \ %numitems(@list))+1)}
Viewer Comments [2 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net