Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Trying to move away from DIM for arrays

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 3rd Jul 2017 11:10
I am trying to declare arrays with myArray as integer[literal,literal] instead of DIM myArray[variable,variable]. But I am having some trouble understanding how to declare an array with variables. I can declare an array with literals, not variables, like myArray as integer[literal,literal], but not myArray as integer[variable,variable]. If I declare the array as myArray as integer[0,0] and then use myArray.length = 1920 (or a variable) and myArray[0].length = 1080 (or a variable), I can print(myArray.length) and get 1920 and print(myArray[0].length) and get 1080, but I can't set myArray[1,1] = 1, it says array out of bounds and that it is empty. I can declare myArray as integer[1920,1080] and then print(myArray.length] and then also get 1920 and print(myArray[0].length) and also get 1080, and now I can set myArray[1,1] = 1. I would like to able to set the array size with variables.
13/0
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 3rd Jul 2017 15:46
This wil NOT work, it will crash at myArray[1,1] = 1:


This WILL work:


In both examples I can print(myArray.length) and get 1920, and print(myArray[0].length) and get 1080.
13/0
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 3rd Jul 2017 20:11 Edited at: 3rd Jul 2017 20:12
You need to allocate a space for [1,1]
In AppGameKit we don't bulk size arrays with myArray[0].length but we set the size of the second dimension of index 0 from the first dimension.
We can set the length of the second dimension for every available first dimension index.

Imagine it like so:

Using AGKv2 Tier1

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Jul 2017 20:47 Edited at: 3rd Jul 2017 20:48
I found the new arrays confusing at first too. My thread might help answer some of your questions.

https://forum.thegamecreators.com/thread/219029

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 4th Jul 2017 19:05
Thank you guys, it is all clear now
13/0

Login to post a reply

Server time is: 2024-11-25 11:02:00
Your offset time is: 2024-11-25 11:02:00