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 / To DIM or not to DIM

Author
Message
PopsHugo
9
Years of Service
User Offline
Joined: 28th Jan 2015
Location: South Africa
Posted: 28th Jan 2015 09:26
Hi,

I have an array defined as follows:

dim TwinTriangle[8] as integer

According to the documentation at http://www.appgamekit.com/documentation/guides/12_array_changes.htm

I should be able to define an array as follows:

TwinTriangle as integer[8]

It doesn't work!

Is this a known problem or am I doing something wrong?

Old grey plodder living in Cape Town
Muckypaws
AGK Developer
12
Years of Service
User Offline
Joined: 21st Oct 2011
Location:
Posted: 28th Jan 2015 11:29
The new nomenclature for defining arrays changed in AppGameKit V2, the recommendation is to not use DIM in that version, although both are supported.

I am able to correctly define



or simply



If I use the same in AppGameKit V1, then it is not supported and you will see an error something like (Variable declared using unknown type)

Therefore continue using DIM in AppGameKit V1

Kind Regards
Jason
www.wonkypix.com
www.muckypaws.com

http://www.wonkypix.com
http://www.appstore.com/jsecconsultancyltd
http://itunes.apple.com/us/app/newtons-nonsense/id473520354?ls=1&mt=8
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Jan 2015 11:45
AGK2 Only:
----------------------
"To maintain backwards compatibility arrays can still be defined with DIM, but version 2 introduces a new method of defining arrays that will become particularly important when defining them in types. Note that both DIM arrays and new style arrays perform exactly the same after they are declared so any functions mentioned here will also work on DIM arrays. The new method is mainly for consistency."
---------------------

You have to use the new method when putting an array in a type.

Quidquid latine dictum sit, altum sonatur
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Jan 2015 11:47
It is fine to create an array as:
TwinTriangle as integer[8]

Works fine here in V2.

Isn't this an implicit definition?

TwinTriangle is an integer array of length 8.

In V2 you can define an empty array like this:
TwinTriangle as integer[]

or even:
global TwinTriangle as meType[]

...for UDT arrays.

When you say it doesn't work what exactly do you mean? I can compile this just fine.


Using AppGameKit V2 Tier 1
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 28th Jan 2015 11:51
Ahh, my bad - I'm still in the pupae stage of going from v1 to v2

I am the one who knocks...
PopsHugo
9
Years of Service
User Offline
Joined: 28th Jan 2015
Location: South Africa
Posted: 28th Jan 2015 12:47
Further to my previous post:

I am using:
AGK IDE 2.0.10 Built on Dec 4 2014


The code is below. I have commented out the DIM statement that worked.

The array definition without the DIM does not work, the comment is that the array is not defined.

Any more suggestions?

//dim TwinTriangle[8] as integer
TwinTriangle as integer[8]
fillTwinTriangle()

function fillTwinTriangle()
TwinTriangle[0] = 7:TwinTriangle[1] = 15:TwinTriangle[2] = 16:TwinTriangle[3] = 17:TwinTriangle[4] = 24:TwinTriangle[5] = 25:TwinTriangle[6] = 26:TwinTriangle[7] = 27
endfunction

tables.agc:441: error: "twintriangle" has not been defined

Old grey plodder living in Cape Town
PopsHugo
9
Years of Service
User Offline
Joined: 28th Jan 2015
Location: South Africa
Posted: 28th Jan 2015 12:48
Further to my previous post:

I am using:
AGK IDE 2.0.10 Built on Dec 4 2014


The code is below. I have commented out the DIM statement that worked.

The array definition without the DIM does not work, the comment is that the array is not defined.

Any more suggestions?

//dim TwinTriangle[8] as integer
TwinTriangle as integer[8]
fillTwinTriangle()

function fillTwinTriangle()
TwinTriangle[0] = 7:TwinTriangle[1] = 15:TwinTriangle[2] = 16:TwinTriangle[3] = 17:TwinTriangle[4] = 24:TwinTriangle[5] = 25:TwinTriangle[6] = 26:TwinTriangle[7] = 27
endfunction

tables.agc:441: error: "twintriangle" has not been defined

Old grey plodder living in Cape Town
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Jan 2015 12:53 Edited at: 28th Jan 2015 12:56
Try adding Global to the front, this line works OK for me in my code, using the same AppGameKit V2 build:

global gBox as tBox[3]

and an example of the array used in a function elsewhere:

function TriggerHighlight(index)

colour = gBox[index].multiplier
...



[EDIT]
DIM is always global, wherever you define it. Are you declaring this array in a function? If so, it is local unless you specify otherwise, with the new syntax.

Quidquid latine dictum sit, altum sonatur
PopsHugo
9
Years of Service
User Offline
Joined: 28th Jan 2015
Location: South Africa
Posted: 28th Jan 2015 13:06
Hi BatVink,

Thanks for the suggestion.

It works if I add Global ahead of the array definition.

Someone needs to update the documentation in this regard.

Thanks

Old grey plodder living in Cape Town
SoftMotion3D
AGK Developer
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 28th Jan 2015 13:59
why are you trying to add as integer to it?

dim TwinTriangle[8]

thats it and it will be integer values and global.

and if you want floats?

dim twintriangle#[8]

you do not need to define as integer or as float with dimmed arrays.

www.sheldonscreations.com

Login to post a reply

Server time is: 2024-05-05 09:24:58
Your offset time is: 2024-05-05 09:24:58