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 / Assigning Array values - Tier 1 v108.19

Author
Message
Funnell7
14
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 18th Jan 2014 21:19 Edited at: 18th Jan 2014 21:23
I vaguely remember seeing an issue a long time ago where you could no longer assign multiple values to an array whilst declaring the variable. Like this;



Is that correct or am I doing something wrong?

EDIT: My Bad... I have many versions of AppGameKit installed and I was using 108.12... This has since been fixed and works fine it 108.19. Need another !
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Jan 2014 14:49
Aren't arrays automatically global anyway and thus don't need that specific global identifier?

Funnell7
14
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Jan 2014 16:11
That's very true, but I have to declare everything, I'm weird like that
JimHawkins
17
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 19th Jan 2014 19:38
Quote: "That's very true, but I have to declare everything, I'm weird like that "


You're not weird - you're sensible. Having arrays as automatically global was NOT a very bright idea.

-- Jim - When is there going to be a release?
Naphier
15
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 23rd Jan 2014 03:48
David Gervais
Retired Moderator
20
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 30th Jan 2014 12:15 Edited at: 30th Jan 2014 12:21
Errm, I think I see something wrong with your sample..



shouldn't that be..



your example has 4 elements defined in a 3 element array.

Or am I failing to understand this? Arrays boggle my mind so do Algorythms lol

Cheers!

Edit: Question.. is the first element in a dim'd array array[0] or array[1] for example...



Funnell7
14
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 30th Jan 2014 12:35 Edited at: 30th Jan 2014 13:01
In Basic (I belive other languages are different) the array also accounts for 0. So in an array of [3], you actually have 4 slots, 0, 1, 2 and 3.

EDIT: So to answer your question, it would be [0]. i.e.

David Gervais
Retired Moderator
20
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 30th Jan 2014 14:02
I was always under the impression that if I dim an array to say 17 "Dim widget[17]" then the actual array pointers were from 0 to 16 (making a total of 17 elements) And my way of compensating was to always add one to the array length to make sure I could use the numbers 1 to 17 for example.. Dim Widget[18] would give me access to the pointers 0 to 17.. and if I ignore '0' all will be fine.

another example is if I am working with a 10x10 grid and need an array to handle the data of what is in each grid spot, I'd Dim grid[11,11] so that I had access to pointers numbered 1 to 10 for each column and row.

now my brain hurts.. 0 = (first element in array) and setting a Dim thingy[3] = an array with 4 elements. I'm not the greatest mathematician but in my brain 1 should always = 1 and 3 should always = 3. not 1=0 and 3=4

but that said, I need to do some tests and make sure this funky math works and then wrap my brain around the 'adjustments' needed to shift my perception of math vs programming math.

Thanks for the reply.

Cheers!

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 30th Jan 2014 14:21
Quote: "
I was always under the impression that if I dim an array to say 17 "Dim widget[17]" then the actual array pointers were from 0 to 16 (making a total of 17 elements)
"


Nah, there's 18, as generally in BASIC array indexes are range inclusive ( zero to count ). So if you dimmed an array with 4 items, that's actually 5 legal indexes (0,1,2,3,4).

Funnell7
14
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 30th Jan 2014 14:55
Quote: "I'm not the greatest mathematician but in my brain 1 should always = 1 and 3 should always = 3. not 1=0 and 3=4"


Same here, I always disregard the first index (the 0) and just start from 1. That makes the most sense to me...
Digital Awakening
AGK Developer
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 30th Jan 2014 15:34 Edited at: 30th Jan 2014 15:35
I often use index 1-X and then use index zero for various things that pops up. I am sadly not consistent in using 1-X, I sometimes use 0-X where X is one less then I need. I got both in RTA and it can be a little confusing at times.

Another confusing thing is that I use positive numbers to indicate hight in tiles from the bottom row and up. So level[0,0] is the bottom left tile. Makes sense because that's where you start. But up in programming is negative. Which can make positioning a bit weird at times. At least the bottom of the level is 0 and everything above is negative numbers. I think that's the best solution after all.

Ancient Lady
Valued Member
22
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 30th Jan 2014 16:59
Not all Basics behave the way AppGameKit Basic does with respect to arrays.

Most actually restrict the array to the declared size. Many start at index 1 and a few at zero.

If you think that you might ever convert your code to Tier 2 (C++), then you should behave as if the starting index is zero and the last is size-1 (the way C++ works). That way, you won't get bit in the butt if you convert your code.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Marl
14
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 30th Jan 2014 17:01 Edited at: 30th Jan 2014 17:04
Quote: "I was always under the impression that if I dim an array to say 17 "Dim widget[17]" then the actual array pointers were from 0 to 16 (making a total of 17 elements)"

It's a language thing
Quote: "as generally in BASIC array indexes are range inclusive ( zero to count )."

There's a generally in BASIC ?
Quote: "I always disregard the first index (the 0) and just start from 1. That makes the most sense to me..."

Me too
Quote: "I often use index 1-X and then use index zero for various things that pops up. I am sadly not consistent in using 1-X, I sometimes use 0-X where X is one less then I need"

Been there.

Language standards aside, I think it suits both sets of people at the cost of a little overhead.

If you understand Dim array[4] to mean indexes 0 to 3 then use 0 to 3
If you understand Dim array[4] to mean indexes 1 to 4 then use 1 to 4

I start at 1, but that's as much to do with data checking as any standard.
I often use zero returns from functions to indicate no result and this applies to functions which return an array index.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Jan 2014 19:33
I try to stay away from the habit of starting with 1 in my arrays, since every other language is 0 to size-1.

Quote: "I often use zero returns from functions to indicate no result and this applies to functions which return an array index."

I return -1 in those cases.

JimHawkins
17
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 31st Jan 2014 00:11
Pascal lets YOU define it:

type Frog = array[-5..5] of integer;
Frogs= array[0..255][-100..100] of MyCroakType;

-- Jim - When is there going to be a release?
Scary Little Rabbit
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location: Chelyabinsk, Russian Federation.
Posted: 31st Jan 2014 18:15
Quote: "Pascal lets YOU define it"
nice.

error #1:
"too many stars, too many stares. disembody."
WIP: MIND!! | free fonts for your AGKs
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Feb 2014 01:18
Wasn't AppGameKit originally supposed to give us the option to require variables be explicitly defined?

Zwarteziel
15
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 9th Feb 2014 22:17
On a sidenote... does anyone get an error when defining an array, while assigning values AND have a comment on the same line? When I compile this:



I get the error: "Only numeric or string literals can be used to initialize a variable declaration at line [nr]."
Naphier
15
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 11th Feb 2014 02:28
Yup... it also errors out if you have space between values...
So just use
dim Numbers[10] as integer =[1,2,3,4,5,6,7,8,9,10]
// this doesn't compile!?

Also there's no need in Tier 1 to explicitly define the array unless it is a UDT. It doesn't cause any problems (now), but the parser for the compiler is easily confused.

Funnell7
14
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 11th Feb 2014 11:42
Isn't it because there is one missing?

dim Number[10] creates 11 slots. So shouldn't it be;

Naphier
15
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 11th Feb 2014 18:05
That would be more correct, but it's not necessary.

The Daddy
17
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 26th Feb 2014 16:07
Pascal does as Jim says, its good like that...logical! But you also get fast, powerful linked lists by default which are ever so useful...especially for things like bullets, tile sets, items collected the list (ironically) goes on!

www.bitmanip.com
All the juicy you could ever dream of!

Login to post a reply

Server time is: 2026-07-26 05:03:59
Your offset time is: 2026-07-26 05:03:59