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.

DarkBASIC Professional Discussion / Need Help with Array

Author
Message
Rikukarasuma
15
Years of Service
User Offline
Joined: 15th May 2011
Location: Ireland
Posted: 27th Jun 2011 15:26
Im doing an update of a game I created called shape invaders(or space invaders) and instead of using an array to create the shapes i did it manually which took a lot of time.
This time I decided to make another one with the use of an array and possibly make more than more level and a boss but the I cant get the array to work because of an error which I dont know how to resolve.
Runtime error 7006 object number illegal.
If someone could point me in the right direction my thanks wont go a miss

Space Invaders

Functions

Space


Yello http://www.youtube.com/user/Rikukarasuma?feature=mhee
Vitamin
15
Years of Service
User Offline
Joined: 15th Oct 2010
Location:
Posted: 27th Jun 2011 16:46
Hey brah,
When you declare an array, I think that number refers to the number of elements in the array, and not the upper subscript. So it really has 0-5 in the first dimension, and 0-3 in the 2nd. I'm not sure if that's right, but to test it, try one less counter in each of your for...next loops in the MakeObject2 function.
Also, this is totally unrelated, but in your game loop, space invader positions aren't being updated, so the MakeObject2 function might work better in the loop.
Rikukarasuma
15
Years of Service
User Offline
Joined: 15th May 2011
Location: Ireland
Posted: 27th Jun 2011 17:00
Hey Vitamin that doesnt seem to be the problem. The same thing is still happening :/
And yeah i always forget to update their positions and then i realise it when i run the program lol

Yello http://www.youtube.com/user/Rikukarasuma?feature=mhee
Vitamin
15
Years of Service
User Offline
Joined: 15th Oct 2010
Location:
Posted: 27th Jun 2011 17:08
Hey brah,
You may have to disregard my first post, LOL...I don't think it has to do with an array out-of-bounds error. I'm not really sure what it is, but maybe it has to do with the fact that you're using floats to refer to elements in the array.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 27th Jun 2011 18:03
It's because Ship=0 and you can't have an object number zero.



Rikukarasuma
15
Years of Service
User Offline
Joined: 15th May 2011
Location: Ireland
Posted: 27th Jun 2011 18:39
Thanks for that Grog but it seems if i put anything after the code you fixed for me it still comes up Object number illegal :/

Yello http://www.youtube.com/user/Rikukarasuma?feature=mhee
Vitamin
15
Years of Service
User Offline
Joined: 15th Oct 2010
Location:
Posted: 27th Jun 2011 18:47
This might be another unrelated issue, but when you call the MakeObject functions, you're passing them UDT's instead of instances of the UDT's.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Jun 2011 20:47
Ship is not declared as a global, therefore it is a local to the MakeObjects2 function. You haven't assigned anything to it, therefore it will have a value of zero. You use it to set the ID in the Alien array, therefore the Alien array ID will be zero. You use that to create an object, but as you can't have an object id of zero, it crashes.

Now say 'thank you' to Grog, and then correct your code

Rikukarasuma
15
Years of Service
User Offline
Joined: 15th May 2011
Location: Ireland
Posted: 27th Jun 2011 22:20
I already said thanks to grog but il say it again. thank you grog.
Okay I understand what your saying but even when I correct that error I cant get the Array to work in the way I want it to make 7 aliens across and 5 rows :/

Yello http://www.youtube.com/user/Rikukarasuma?feature=mhee
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Jun 2011 00:43 Edited at: 28th Jun 2011 00:44
@ IanM:

Thanks


@ Rikukarasuma:

Np. That code snip was to show you what was going on (and to teach you how to find errors like that yourself). For the actual fix you just move the setting of the starting object number and finding of the first free object number into the FOR/NEXT for the alien creation.



Now if you didn't know already IanM made some amazing commands in a plugin called Matrix 1 Utilities Plugin. One of the cool commands is FIND FREE OBJECT() which will do the same as your REPEAT/UNTIL loop to find the free object number (but much faster).



Just click on IanMs signature to download it.

Edit: Your indentation is all weird... are you using just TAB or TAB with spacebar?

Rikukarasuma
15
Years of Service
User Offline
Joined: 15th May 2011
Location: Ireland
Posted: 28th Jun 2011 00:57
Thanks a million Grog! i will try that out right away
okies i will check that out
I do use Tab for my indents

Yello http://www.youtube.com/user/Rikukarasuma?feature=mhee

Login to post a reply

Server time is: 2026-07-10 19:07:09
Your offset time is: 2026-07-10 19:07:09