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 Chat / Define an array with a dynamic size?

Author
Message
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Jun 2018 15:16
Am I just having a stupid moment this morning? Or can I really not calculate the size of an array?

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Bengismo
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 13th Jun 2018 15:54 Edited at: 13th Jun 2018 20:53
Add a dim and change the period to a comma



That compiles and works

....and technically....you dont need the = in the #constant lines
#CONSTANT TILE_X x
works ok too but also works if you leave the "=" in there
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Jun 2018 18:47
I know about the equals, I was just trying different things. Period was a typo when I copied it in. doh.

I thought we didn't need to use DIM anymore? I just tried your solution and it still gives the same error.

main.agc:39: error: Unexpected token "x", Array dimension must be an integer literal or a constant (line 7 in the example)
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
PSY
Valued Member
2
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 13th Jun 2018 19:08 Edited at: 13th Jun 2018 19:16
Setting the size of an array using an arithmetic expression or a standard variable is not allowed.

Not allowed:
map as integer[SIZE*3]

Not allowed:
tile as integer = 666
map as integer[tile]


EDIT:
The following code works using DIM:



PSY LABS Games
Coders don't die, they just gosub without return
Bengismo
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 13th Jun 2018 20:54 Edited at: 13th Jun 2018 20:59
This compiles and works

x = getVirtualWidth() / 32
y = getVirtualHeight() / 32

#CONSTANT TILE_X = x
#CONSTANT TILE_Y = y

dim map[TILE_X, TILE_Y] as Tile

As long as the type tile actually exists.....
Phaelax
DBPro Master
15
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Jun 2018 21:03
I don't know why that solution wasn't working for me earlier but it is now.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Markus
Valued Member
14
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 18th Jun 2018 14:56
you can redim with .length =
yes Dim was the older syntax.
https://www.appgamekit.com/documentation/guides/12_array_changes.htm
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : NVIDIA (390.65) GeForce GTX 1050 Ti : Mac mini OS High Sierra (10.13)

Login to post a reply

Server time is: 2018-08-17 18:12:03
Your offset time is: 2018-08-17 18:12:03