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 / Clear out an Array

Author
Message
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 31st Jul 2015 21:10 Edited at: 31st Jul 2015 21:12
Let's say I have an array like so:



I have since populated the array with a bunch of stuff, now I would like to clear it out. As if I had just created the array.
Would something like so work?:



Or do I have to loop through the entire array?:





AGK: 2.0.14b Development System: Windows 7 Pro 64-bit
Android Device: Samsung Galaxy Tab 2 7inch (gt-p3113) Android OS: KitKat 4.4.4 (Slimkat Rom)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 31st Jul 2015 22:44
This should do it, although I haven't tested:

Array[0].length = -1
Array[0].length = 99

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Aug 2015 10:26
Arrays in Version 2
http://www.appgamekit.com/documentation/guides/12_array_changes.htm

AGK 108 (B)19 + AppGameKit (Steam) V2 Beta .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 5th Aug 2015 21:15 Edited at: 5th Aug 2015 21:17
Now I am just confused. As far as I knew arrays didn't use index 0 (zero), they started at 1.

If they start at 0, how does this code work then?



I would think it would throw an error every time i try to put something into index 2 (only 0 and 1 are valid indexes). Does AppGameKit automatically resize the array?

AGK: 2.0.14b Development System: Windows 7 Pro 64-bit
Android Device: Samsung Galaxy Tab 2 7inch (gt-p3113) Android OS: KitKat 4.4.4 (Slimkat Rom)
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 5th Aug 2015 21:27
AGK starts at 0 and ends with whatever you have declared.

MyArray[2] has 0, 1, and 2.

Using AppGameKit V2 Tier 1
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 5th Aug 2015 22:38 Edited at: 5th Aug 2015 22:39
I see that makes sense.

Print(TestArray.length) seems to give the size of the first dimension. How would i get the size of the other dimensions?



I tried it with the [#] but it always gives me "3"

AGK: 2.0.14b Development System: Windows 7 Pro 64-bit
Android Device: Samsung Galaxy Tab 2 7inch (gt-p3113) Android OS: KitKat 4.4.4 (Slimkat Rom)
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 6th Aug 2015 06:18
I think I get it now.

Array.length -> dimension 1
Array[0].length -> dimension 2
Array[0,0].length -> dimension 3
etc.

Wow that is ugly. I am guessing there is some reason to it, backwards compatibility perhaps?

AGK: 2.0.14b Development System: Windows 7 Pro 64-bit
Android Device: Samsung Galaxy Tab 2 7inch (gt-p3113) Android OS: KitKat 4.4.4 (Slimkat Rom)
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 6th Aug 2015 08:20
The -1 trick worked, thanks!

AGK: 2.0.14b Development System: Windows 7 Pro 64-bit
Android Device: Samsung Galaxy Tab 2 7inch (gt-p3113) Android OS: KitKat 4.4.4 (Slimkat Rom)

Login to post a reply

Server time is: 2024-11-25 19:30:11
Your offset time is: 2024-11-25 19:30:11