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.

AppGameKit Classic Chat / [AGK2] Delete and/or Resize Multidimensional Array?

Author
Message
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 19th Dec 2014 06:00
Ok, so I'm trying to update my Tiled TMX Map Loader code for AGK2 (don't worry, I'll maintain an AGK1 version as well ), and I'm having issues with arrays.

Part of the old (AGK1) code does this:



TMX_Map is a 2D array. The point of that code, IIRC, is to reset the array to 0. Basically to get rid of all data and make it 0-length. How would I achieve this in AGK2?

Also, that same array needs to be global, but cannot be sized at the start of the program, so (again) I have to be able to resize (or redefine) a multidimensional array mid-program.

I'd appreciate any help on this

Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Dec 2014 18:23 Edited at: 19th Dec 2014 20:32
array.length = -1 "an empty array"

http://www.appgamekit.com/documentation/guides/12_array_changes.htm

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Dec 2014 20:12
To set the full multi-dimensional array to zero length TMX_Map[].length = -1
To set the first dimension to zero length TMX_Map[0].length = -1
To set the second dimension to zero length TMX_Map[0,0].length = -1
...
etc.
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 21st Dec 2014 12:58
Quote: "To set the full multi-dimensional array to zero length TMX_Map[].length = -1
To set the first dimension to zero length TMX_Map[0].length = -1
To set the second dimension to zero length TMX_Map[0,0].length = -1"


Talk about confusing... Question:

According to the docs, you would do "TMX_Map.length = -1". Is it necessary to have the square-brackets if the array is multidimensional?

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 21st Dec 2014 13:28 Edited at: 21st Dec 2014 13:29
My bad - empty square brackets are not required.

After a quick test it seems that everything I said was wrong

This gives the results 5, 10, 20 as expected from the help files. Although I don't like it. I would prefer the result to be 35, 5, 10 but hey, that's just how it is.


myArray.length = -1 clears all of the array
myArray[0,0].length = -1 clears the last dimension of the array, so the results are now 5, 10, -1
myArray[0].length = -1 clears the last two dimension of the array so the results are now 5, -1 followed by an error unless you comment out the last print statement.

I don't like how it works. I think myArray.length should return the complete length of all dimensions and then [0] would refer to the first dimension, [0,0] the second etc. but it doesn't seem to work that way.
Clonkex
Forum Vice President
13
Years of Service
User Offline
Joined: 20th May 2010
Location: Northern Tablelands, NSW, Australia
Posted: 22nd Dec 2014 00:59
Quote: "After a quick test it seems that everything I said was wrong"


lol

Quote: "myArray.length = -1 clears all of the array
myArray[0,0].length = -1 clears the last dimension of the array, so the results are now 5, 10, -1
myArray[0].length = -1 clears the last two dimension of the array so the results are now 5, -1 followed by an error unless you comment out the last print statement."


Ideally it should be something like this:

myArray.length == either isn't legal or returns size of all dimensions added up.
myArray[].length == size of first dimension (notice no 0)
myArray[][].length == size of second dimension
etc.

The only issue with using empty brackets method (ie. [][]) is that it then becomes inconsistent with the way the rest of the array system works (ie. [0,0]). Still, it should still be possible to correct the confusing nature of not including any brackets.

Quote: "myArray[0].length = -1 clears the last two dimension of the array so the results are now 5, -1 followed by an error unless you comment out the last print statement."


I think I understand how it all works now, except for this... why would it cause an error? Surely we should just see 5, -1, -1? Unless you can add/remove dimensions dynamically

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 22nd Dec 2014 08:28
Quote: "I think I understand how it all works now, except for this... why would it cause an error?"


I don't know but try it and you'll see that it does. Maybe something for Paul to look at.

Login to post a reply

Server time is: 2024-03-28 23:53:05
Your offset time is: 2024-03-28 23:53:05