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 / Subscript out of bounds at line...

Author
Message
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 6th Mar 2012 23:58
Hi, I just ran into a weird error in my game, when I try to run the game I get the error, subscrit out of bounds at line 24 inside weapons.agc. I have no idea what it means nor any idea of how to fix it.

What does it mean and how can I get rid of it?

I have attatched the code where the errror appears



I think iv'e seen the error before but I can't remember what I did to fix it though...
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 7th Mar 2012 00:02 Edited at: 7th Mar 2012 00:04
it means that you're requesting an array space out of bounds.

To remember :

Dim Rocket[50] permits to go from Rocket[0] to Rocket[49] ..

So maybe you have to change to :

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 7th Mar 2012 00:03 Edited at: 7th Mar 2012 00:12
It usually means you tried to access an array beyond what you dimmed

As you didn't include the dim statements in the code it's difficult to say more than that.

Edit: 2nd past the post again

@MikeMax

You just beat me to it.

Oh and in AppGameKit, Dim Rocket[50] does actually allow from 0 to 50.

More likely Player.RocketAmount somehow got too big and so i is counting beyond the dim'd size of the array in the line with the error.

But again without seeing the dim statement, it's difficult to say why.
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 7th Mar 2012 08:34
Thanks to you I found the problem, turns out I had typed RocketAmount instead of player.rocketamount

Thanks for the help!
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 7th Mar 2012 12:35 Edited at: 7th Mar 2012 12:36
Edit: double post sorry
MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 7th Mar 2012 12:35
@ Marl


Ho yes you're right ... (but i consider that as an AppGameKit bug :p)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 12:39
Quote: "Ho yes you're right ... (but i consider that as an AppGameKit bug :p)"

I consider it an opportunity! I use the zero slot to store the number of used slots so I never get this exact error message. That way you can dynamically change the size of the array on the fly too!

All of my arrays are dim'd like this:


Also it's standard behaviour for arrays to start at zero isn't it (at least in most of the languages I've used)?

MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 7th Mar 2012 13:08
To start at zero yes .. but end to [SIZE]-1 too :p not [SIZE].

A dimension of 50 means 50 slots. not 51

So yes in this case the ZERO slot can be cool to count elements. (there is no sizeof() in Tier1 ? :p)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 13:14
I see what you mean. No there is no sizeof() in Tier 1.

I prefer using the [SIZE] value as it is personally because it works well with using an empty zero slot.

I guess it's confusing because it's half done one way and half the other. I am quite happy with how it works in Tier 1 myself.

MikeMax
AGK Academic Backer
12
Years of Service
User Offline
Joined: 13th Dec 2011
Location: Paris
Posted: 7th Mar 2012 13:28
Good luck to convert Tier1 code to Tier2 with this method You will have to redim each array to size+1 to prevent read/writes out of memory allocated

( [0 -> Size-1] is the standard on most of the languages .. (C++,Java, etc...))
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 7th Mar 2012 13:50
Quote: "Good luck to convert Tier1 code to Tier2 with this method"

My guess is that if this is a problem TGC will be quite likely to find that out first since they are already doing games cross platform in AGK.

Quote: "( [0 -> Size-1] is the standard on most of the languages .. (C++,Java, etc...))"

Yes, I thought you were referring to arrays starting at zero rather than being sized in this way, my misunderstanding.

I use C# at work mainly and it has "foreach" which is a far easier method of looping through data.

Login to post a reply

Server time is: 2024-11-23 05:23:29
Your offset time is: 2024-11-23 05:23:29