Page 1 of 1

Ruby - What's the best way to create a 3-dimensional array?

Posted: Tue Sep 23, 2014 12:18 pm
by zoobooboozoo
Hi guys,
I'm new to ruby and flowstone and I want to know what's the best methods for creating a 3-dimensional array, I've seen some different methods online and thought I'd better get your input on that.

The array dimensions are: 25, 3, 5 (not that it matter so much :) )

thx i advance for the help.

also: I had a problem with the knobs. when I take a knob and connect its output to ruby input it the corresponding value inside the ruby module doesn't update when I turn the knob around. how can I solve this?

Re: Ruby - What's the best way to create a 3-dimensional arr

Posted: Tue Sep 23, 2014 12:29 pm
by tulamide
zoobooboozoo wrote:I'm new to ruby and flowstone and I want to know what's the best methods for creating a 3-dimensional array, I've seen some different methods online and thought I'd better get your input on that.

Nesting blocks is a comfortable way to create multi-dimensional arrays:

Code: Select all

a3d = Array.new(4) {Array.new(3) {Array.new(2)} }


Accessing that array's cells is also straight-forward:

Code: Select all

a3d[0][1][1] = 5
n = a3d[2][0][0]

Re: Ruby - What's the best way to create a 3-dimensional arr

Posted: Wed Sep 24, 2014 10:43 pm
by zoobooboozoo
Thanks, works great.