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 / Array size question in AGK

Author
Message
Jeku
Moderator
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 7th Nov 2015 19:25 Edited at: 7th Nov 2015 19:27
Here's code from the official AppGameKit 2 arrays documentation.



If I declare an array in a C-scripted language like PHP with a size of 5, then I can ONLY put 5 elements into that array. Yes, the first index is 0, so the last index would be 4. But no matter how you look at it, there can ONLY be 5 elements in that array (0, 1, 2, 3, 4). In a BASIC language like AppGameKit, it is the same, but with an index starting with 1 (1, 2, 3, 4, 5).

Question: is this showing that AppGameKit is flexible enough to allow the programmer to add extra elements to an array, or is there an error in documentation? I've never seen a language where you declare the size of an array, and it gives you a size + 1.

EDIT:

Also, is there a way to do a 2D or 3D array? Can't seem to find that in the docs.
Senior Software Engineer - RotoGrinders
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Nov 2015 19:41 Edited at: 7th Nov 2015 19:42
in basic its normal, u define the upper limit that includes the 0 index.
normal access
for index=1 to count

it have commands to add/insert data so it should not expand automatic.

at this page u can see a multi dimension array.
http://www.appgamekit.com/documentation/guides/12_array_changes.htm
AGK (Steam) V2.0.15b : Windows 10 Pro 64 Bit : AMD (15.201.1151.0) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 7th Nov 2015 20:01
If I could choose I would remove the 0 element and have it go from 1 to index, but it is a part of the language now so we must continue to support it. I did consider writing the documentation as if the 0 element didn't exist and pretend it goes from 1 to index, but then when someone discovers the 0 element they are going to be confused, so I did my best to explain it in there.

A 2D array can be created like so
AppGameKit supports up to 6 dimensions.
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 7th Nov 2015 22:03
Paul Johnston wrote: "If I could choose I would remove the 0 element and have it go from 1 to index, but it is a part of the language now so we must continue to support it."

You could create something like a preprocessor directive so the developer can choose 0 or 1 as starting point for arrays. Like so
Jeku
Moderator
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 8th Nov 2015 19:18
Quote: "in basic its normal, u define the upper limit that includes the 0 index.
normal access
for index=1 to count"


Normally in BASIC, you define the upper limit and it doesn't include 0, as Paul Johnston stated. At least I know now how to think about arrays in AGK. I've been using them already all over my project but didn't use the 0 index, so it's probably just fine Thanks all!
Senior Software Engineer - RotoGrinders
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Nov 2015 22:29
this old visual basic includes 0 index but there is a "Option Base 1"
so by default is Dim a(5) As Integer '0 to 5
with Option Base 1
1-5
AGK (Steam) V2.0.15b : Windows 10 Pro 64 Bit : AMD (15.201.1151.0) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 10th Nov 2015 05:23

Quote: "Normally in BASIC, you define the upper limit and it doesn't include 0"


nah, BASIC normally zero inclusive.


Login to post a reply

Server time is: 2024-11-25 15:49:39
Your offset time is: 2024-11-25 15:49:39