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 / Bit puzzled to why this Array wont work?

Author
Message
Gibbon28
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location: Derbyshire, UK
Posted: 25th Oct 2012 13:25
I am simply calling this:

Global dim myValues as integer = [5,9,4,8,3,7,2,6,1,10]

But print(str(myValues[5])) = 0????

Ive also tried:

Global dim myValues = [5,9,4,8,3,7,2,6,1,10]

But then it wont compile... even though im following this...

http://www.appgamekit.com/documentation/language/5_dim.htm

Thanks
Andy
Gibbon28
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location: Derbyshire, UK
Posted: 25th Oct 2012 13:54
For instance, this doesnt work:



all 3 prints are 0

Thanks
andy
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 25th Oct 2012 14:02 Edited at: 25th Oct 2012 14:07
I'm no expert on the Basic, but shouldn't it be:

Global dim myValues[10] as integer = [5,9,4,8,3,7,2,6,1,10]

This is a static array, so the compiler needs to know how long it is!

EDIT: I seem to remember reading that a dim of [10] in AppGameKit actually allocates 11 (0..10), but I may be wrong. Often am.

It's a bit clearer in Pascal:

var myValues : array [0..9] of integer;

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Rickynzx
12
Years of Service
User Offline
Joined: 19th Dec 2011
Location: Troon, Scotland
Posted: 25th Oct 2012 14:08 Edited at: 25th Oct 2012 14:12
You need to enter the number of items in array then it will work.

global dim myValues[10] as integer = [5,9,4,8,3,7,2,6,1,10]

EDIT:
print(str(myValues[5])) actually prints number 7 because arrays start at item number 0
Gibbon28
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location: Derbyshire, UK
Posted: 25th Oct 2012 14:12
Sorry was a typo in the forum not code.

my code does display the size.

Global dim myValues[10] as integer = [5,9,4,8,3,7,2,6,1,10]

Still doesnt work.

Thanks
Andy
Ian Rees
AGK Developer
11
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 25th Oct 2012 16:05 Edited at: 25th Oct 2012 16:18
I just copied your code from above and pasted it into a new project - it worked fine for me:



If you put the above code into a new project does it work?

E

http://www.superiorinteractive.com/galaforceworlds/

Attachments

Login to view attachments
Gibbon28
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location: Derbyshire, UK
Posted: 25th Oct 2012 16:12
How strange, what version are you using?

Im using 108.

Thanks
Andy
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Oct 2012 18:14
You don't need to type GLOBAL DIM array[]. Arrays are global by default, so you just need DIM array[].

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Ian Rees
AGK Developer
11
Years of Service
User Offline
Joined: 3rd May 2012
Location: Wales, UK
Posted: 25th Oct 2012 19:39 Edited at: 25th Oct 2012 19:39
Quote: "How strange, what version are you using?

Im using 108."


I'm using 1076.

E
Gibbon28
11
Years of Service
User Offline
Joined: 22nd Oct 2012
Location: Derbyshire, UK
Posted: 26th Oct 2012 10:43
Hmm how can i report a bug about v108?

Thanks
Andy
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Oct 2012 15:52
Quote: "Hmm how can i report a bug about v108?"
http://code.google.com/p/agk/issues/list


this.mess = abs(sin(times#))

Login to post a reply

Server time is: 2024-04-27 18:48:08
Your offset time is: 2024-04-27 18:48:08