Old 12-14-2018, 10:24 AM   #1
Chris T
Human being with feelings
 
Join Date: Dec 2010
Posts: 48
Default Ho to implement more than one array of variables

Hi

@init
delta[0]=77;
m1[0]=84;
m2[0]=104;
m3[0]=100;

leads to all 4 variables being set to 100. How can I implement multiple arrays?

Thanks
Chris
Chris T is offline   Reply With Quote
Old 12-14-2018, 10:57 AM   #2
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

You have to use offsets within the one single array that you're given. You do this by assigning the offset to the array-variable - for example:

Code:
@init

delta = 0;
m1 = 256;
m2 = 512;
m3 = 768;

delta[0]=77;
m1[0]=84;
m2[0]=104;
m3[0]=100;
This will now assign 77 to position 0, assign 84 to position 256, and so on.

The code above separates the arrays by 256 points - so delta[255] is fine, but delta[256] will point to the same section of memory as m1.
__________________
JSFX set | Bandcamp/SoundCloud/Spotify
geraintluff is offline   Reply With Quote
Old 12-14-2018, 05:07 PM   #3
Chris T
Human being with feelings
 
Join Date: Dec 2010
Posts: 48
Default

Thanks, that way it works!
Chris T is offline   Reply With Quote
Old 12-15-2018, 06:23 AM   #4
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,677
Default

Just to add to the above. When you use:
Code:
delta[0]=77;
m1[0]=84;
m2[0]=104;
m3[0]=100;
They all use the same area of memory, as delta, m1, m2 and m3 are all initialised to a value of 0. And 0[0] means memory address 0 offset by 0, that is address 0.

Using
Code:
delta = 0;
m1 = 256;
m2 = 512;
m3 = 768;

delta[0]=77;
m1[0]=84;
m2[0]=104;
m3[0]=100;
as geraintluff posted, then the 4 "arrays" (really sequences of variables) are initialised to point to discrete addresses; delta[0] is address 0, m1[0] is address 256, m2[0] is address 512 etc

-------------------------
I often use something like:
Code:
start_alpha = 1024;                                 noof_alphas  = 256;
start beta = start_alpha + noof_alphas;       noof_betas   = 256;
    beta_type  = start_beta;
    beta_value = start_beta + noof_betas;
start gamma = start_beta + noof_betas *2;  noof_gammas = 256;
end_gamma = start_gamma + noof_gammas;
// .... note that the beta array has two items in it
That makes moving them / changing the array size easier.
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.