Forum
Arrays question - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: Arrays question (/showthread.php?tid=749)



Arrays question - rikokun - 11-06-2016

Hallo.

So i was looking for an answer on the forums but couldn't find it.
How do i change content of an array?
I have game maps in array of course and i want to load different screen layout to the same array i used before.

I know i can do:

dim a(10) as ubyte => {1,2,3,...}

Now how to change it to something else?

In the olden days i used data to fill arrays quickly, dut that doesn't seems to be case anymore ^_^

edit: well i guess i can make a 3D array and instead of loading data into 2D array, simply switch to another layer of 3D array. But i dont know what is better memory-wise. The data needs to be there any way, but i don't know, i just don't like having huuuuge 3D array of all the screens in the game in memory at all times...
Plus i was hoping i could load data to new area from file...


Re: Arrays question - boriel - 11-09-2016

rikokun Wrote:Hallo.
edit: well i guess i can make a 3D array and instead of loading data into 2D array, simply switch to another layer of 3D array. But i dont know what is better memory-wise. The data needs to be there any way, but i don't know, i just don't like having huuuuge 3D array of all the screens in the game in memory at all times...
Plus i was hoping i could load data to new area from file...

I'm not sure I understand your question.
You mean change the ARRAY Shape (dimensions)? Unfortuntely this is not implemented (yet) in ZX BASIC. This are called Dynamic Arrays. They are a bit slower but better under many circumstances.
If your question is not related to this, please tell me so I can help you.


Re: Arrays question - rikokun - 11-10-2016

No, i ment something like

Dim a(4)

let a(0-4) = 1, 2, 3, 4, 5

I know you can put the values stright in the array when you declare it, but it would be nice to be able to be able to change its content later

Never mind, i found a way arround it by poking it using defb and reading data straight out of memory Smile


Re: Arrays question - britlion - 03-15-2017

rikokun Wrote:No, i ment something like

Dim a(4)

let a(0-4) = 1, 2, 3, 4, 5

I know you can put the values stright in the array when you declare it, but it would be nice to be able to be able to change its content later

Never mind, i found a way arround it by poking it using defb and reading data straight out of memory Smile

I'm confused by this question, too. It's an array - of course you can change the contents.

let a(3)=8 - and you've changed the fourth value (remember it starts at 0) to 8...