de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Multidimensional Array
PostPosted: Sat Aug 03, 2013 3:14 am 
Offline
Active member
User avatar
I have been trying to work out the syntax of multidimensional or nested arrays.

Would you be able to tell me how I define these and call them?


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sat Aug 03, 2013 10:12 am 
Offline
Site Admin
User avatar
Multidimensionnal arrays are created as arrays of arrays. See a simple array of strings :
Code:
//create
def tools = ["whip","cane","paddle"]
//replace "cane" with "stick"
tools[1] = "stick"
//get one, the second one
showPopup(tools[1])

//iterate (read all)
for(def tool : tools)
  showPopup(tool)

Now a 2-dimensions array, that is an array of array of strings :
Code:
def tools2 = [["whip","cane","paddle"],["whips","canes","paddles"]]
tools2[0][1] = "stick"
tools2[1][1] = "sticks"
showPopup(tools2[0][1])

//tools2 is an array of array of strings, tools is an array of strings, tool is as string
for(def tools : tools2)
  for(def tool : tools)
    showPopup(tool)


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sun Aug 04, 2013 1:38 pm 
Offline
Active member
User avatar
Thank you!

I was defining them correctly but calling them like this: tools2[0,1]

Appreciate the help ;)


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sat Aug 10, 2013 3:11 am 
Offline
Active member
User avatar
Fresh multi dimensional array question. How can I call tools2.size to count the main items of an array ie: [[0,0],[1,1],[2,2]] = 3? I keep getting 2.


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sat Aug 10, 2013 9:00 am 
Offline
Site Admin
User avatar
Well, I tried the code below, and got 3 :
Code:
def tools2 =  [[0,0],[1,1],[2,2]]
showPopup(tools2.size)


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sat Aug 10, 2013 5:01 pm 
Offline
Active member
User avatar
Lovely, thanks for all the help Doti. That is the last thing i need to finish my script. Gonna just do some polishing then I'll upload it.


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sun Aug 11, 2013 3:57 am 
Offline
Active member
User avatar
Scratch that, just one more question (columbo style). If I wanted to add additional data lines into a multi-array at a later stage, how would you do it?


Top
 Profile Send private message 
 
 Re: Multidimensional Array
PostPosted: Sun Aug 11, 2013 10:36 am 
Offline
Site Admin
User avatar
Use .add()
Code:
def tools2 =  [[0,0],[1,1],[2,2]]
tools2.add([3,3])
showPopup(tools2.size) // => 4


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


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 post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.