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.

Author
Message
Behdadsoft
14
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th May 2015 12:11 Edited at: 14th May 2015 14:40
Hi.

I want change my enemy value when timer()>=10, but when timer() is same or grate than 10, show me below error:

Subscript is out of bounds at line 46

I don't know how can change value without error.

this is an example code:



Please Guide Me.

Thanks.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th May 2015 13:04
It looks like your array is not 10 elements long (is it 5 elements?).
When you change MaxLength, you are trying to look at elements that don't exist in or all of:

enemy[]
enemyX#[]
enemyY#[]

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Behdadsoft
14
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th May 2015 13:33 Edited at: 14th May 2015 14:39
Quote: "It looks like your array is not 10 elements long (is it 5 elements?)."


no, sorry for my code. this is fixed code:



for can change enemy length I used another variable but give me error.
okee
9
Years of Service
User Offline
Joined: 1st May 2014
Location: Ireland
Posted: 14th May 2015 14:12
When you dimension the array you're giving it 10 elements
The first element in the array is 0 last will be 9
If you change the for loop to
For c = 0 to MaxEnemy - 1

It should work
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th May 2015 16:19
There's a bit of an anomaly in arrays. If you

global dim enemy[5]

You get array elements 0 to 5 (6 elements)
So you don't need to use

For c = 0 to MaxEnemy - 1

like you might in other languages.

When you change MaxEnemy to 10, you also need to change the array length to 10. The array has no connection to the variable MaxEnemy once you have declared the array length. Here is your original code with an amendment (compatible with AppGameKit V1 or V2):



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Behdadsoft
14
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th May 2015 16:32
Quote: "When you dimension the array you're giving it 10 elements
The first element in the array is 0 last will be 9
If you change the for loop to
For c = 0 to MaxEnemy - 1

It should work"


don't work.
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th May 2015 17:26
see my post

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Behdadsoft
14
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th May 2015 18:02
Thanks BatVink, now work.

I have another problem with this change and if feel need your help aks again.

Login to post a reply

Server time is: 2024-03-28 15:54:47
Your offset time is: 2024-03-28 15:54:47