Table init and size


#1

Newbie questions about tables: what should I write in the 'init' window? in order to create a table containing 32 values from 0 do 127 (in terms of size I guessed 'table/alloc 8b' should do the job)


#2

create a new table object, right click - help smile

then select the top right table (actually most tables) and click init/edit, and you will find an example.


#3

I thought that this init script with numbers meant something stuck_out_tongue Can I just blindly copy this to every new table and it will work?


#4

well I guess it depends what you want to initialise with the table with, (I think it defaults to zeros)
its standard C code...
so in your example you want to initialise to 0 to 127, its

int i;
for(i=0;i<LENGTH;i++)
    array[i] = i % 127;

you may be tempted to have written

 array[i] = i;

but that would of course then go higher than 127 if the LENGTH > 127
its not difficult even if your not a C programmer, often just add the equation you want as array[i] = ??? (using i)

note: the important point is the for loop ensures it doesn't go beyond LENGTH which is the size of the table.

(the reason its in C, and you don't just fill with numbers manually, is it would be pretty tedious typing in lots of numbers, and usually its better to algorithmically determine values.
you can enter fixed numbers e.g. (don't use the for loop)

 array[0] = 1;
 array[1] = 2;
 array[3] = 5;

just don't go beyond LENGTH smile