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 / [BUG?] Can't populate arrays on declaration within a function

Author
Message
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Dec 2016 08:16
Hey,

Try this:

I would expect that to print the number 5, 4, 3, 2, 1 but instead I get five zeros.
However, if you make stuff global then it woks as expected but that makes no sense!
AGK V2 user - Tier 1 (mostly)
Fluorescent
FPSC Reloaded TGC Backer
19
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 19th Dec 2016 08:57
I found the same thing a while back, https://forum.thegamecreators.com/thread/217006 and as blink0k mentions in the last post
blinkOk wrote: "Initializing arrays when they are defined within a function does not work. you have to manually initialize the array"

will solve your problem I think.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Dec 2016 09:28
Thanks, but I wasn't looking for a work-around. I've already got one of those as you can see from the global command.
I was pointing out a bug within AppGameKit that requires fixing.
AGK V2 user - Tier 1 (mostly)
damothegreat
User Banned
Posted: 19th Dec 2016 11:08
Does this work in the older AppGameKit version(s)

If it did work, then bug in this new update

If no then maybe @Paul could answer why it was chosen to not work programmatically as a rule in AGK

I think it does require @Paul to investigate in anyway

Damo
Using Tier 1 AppGameKit V2
Started coding with AMOS
Anything is possible if put mind to it
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 19th Dec 2016 23:48
Fixed for the next version. Global arrays are created as soon as the app starts, even if they are defined in a function. But local arrays are created on the stack when the function gets called, and they weren't setting their default values properly in that case.

Login to post a reply

Server time is: 2024-11-24 22:34:19
Your offset time is: 2024-11-24 22:34:19