eddhell Posted December 3, 2019 Share Posted December 3, 2019 I've read nanochess' book over and over, and I am just not understanding how to fill an array with specified data from a DATA statement. I know you can use a For...next loop as a counter to "fill" the array, but I don't understand how to point the array to the specific DATA statements I want to use. ok, so basically, I'm trying to fill an array with 10 preset numbers. Here's the only way I could get it to work so far: DIM sqx(10) read_array: RESTORE sqx FOR x = 0 to 9 READ sqx(x) NEXT x sqx: DATA 24,24,96,144,144,80,24,32,24,32 .....and it SEEMS to work fine. BUT -When I try to add another array, how do I point it to another section of DATA? Here's what I tried and it didn't work: DIM sqx(10) DIM sqy(10) read_array: RESTORE sqx RESTORE sqy FOR x = 0 to 9 READ sqx(x) READ sqy(x) NEXT x sqx: DATA 24,24,96,144,144,80,24,32,24,32 sqy: DATA 64,16,32,24,80,72,56,64,24,16 there's something i'm just not getting with this...does the label before the DATA have to match the array name? or is it all DATA statements read in sequential order? Quote Link to comment Share on other sites More sharing options...
skywaffle Posted December 4, 2019 Share Posted December 4, 2019 I thought restore only pointed to one set of data statements, although it is not a command I typically use. You could do something like this instead to store the contents of the two tables into two separate arrays: DIM sqx(10) DIM sqy(10) read_array: FOR x = 0 to 9 sqx(x) = table_x(x) sqy(x) = table_y(x) NEXT x table_x: DATA 24,24,96,144,144,80,24,32,24,32 table_y: DATA 64,16,32,24,80,72,56,64,24,16 1 Quote Link to comment Share on other sites More sharing options...
eddhell Posted December 4, 2019 Author Share Posted December 4, 2019 that was it man! I don't know why I thought i had to use some kind of READ command to fill it. just overthinking it i guess. THANKS! Quote Link to comment Share on other sites More sharing options...
skywaffle Posted December 4, 2019 Share Posted December 4, 2019 You're welcome. If you are not changing the values of these arrays, you can also reference the tables directly rather than using the limited RAM to store what is already in ROM. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.