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 Discussion / object exists help/error?

Author
Message
Southside Games
10
Years of Service
User Offline
Joined: 1st Jan 2010
Location: Don\'t tell me what to do!
Posted: 6th Feb 2012 23:05
Hello!

For an RTS I'm making I have an array that holds the unit data. I'm coding the part were it ells you how many units you have and the unit cap. however it keeps telling me the object number is illegal. I have the array set up so it will record the object number in the first slot


what else is weird is I can have it print array(find) and it will show the object number. I tried dumping the array into another variable but that turns up the same problem. any ideas?

Thanks much!

29 games
14
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 7th Feb 2012 00:52
I think you might need to post your entire code. The bit you posted doesn't really give me any idea of what the problem is. My guess at the moment is that there's a disconnect between the numbers you have stored in the array and the actual numbers for the objects that have been created. That's probably where I'd start looking.

Also, the variable maxunits# should really be an integer not a float. I don't think this is the source of the error but it won't help.
Southside Games
10
Years of Service
User Offline
Joined: 1st Jan 2010
Location: Don\'t tell me what to do!
Posted: 7th Feb 2012 02:20 Edited at: 7th Feb 2012 02:26
ok. I'll change the float. but now for the topic at hand.

This is how it would add the info.


something else is that it will work fine if I put a number insted of "find"

as so.


that works(even though it only turns up the first slot it wont crash DBP)

Thanks for the reply

edit: I Found also that if I just use find it will work and turn up results



so whatever it is it seems to come from find being inside an array.

Southside Games
10
Years of Service
User Offline
Joined: 1st Jan 2010
Location: Don\'t tell me what to do!
Posted: 7th Feb 2012 02:41
Well I fixed it. I found what I was doing wrong is I never put a value in any other port of the array. so it was checking if object zero existed. For some reason I though it was going to check for zero by itself. silly me

Thanks for your reply!

TDK
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Apr 2012 17:11 Edited at: 15th Apr 2012 17:13
Quote: "teamone(1) = 5
teamone(1,1) = 1 `tank
teamone(1,2) = 100
teamone(1,3) = 5"


At first glance, I was sure that this wouldn't run in DBC because of the first line. It didn't. However, oddly enough the first line was OK - the missing colon on line 2 caused the problem!

So, I point the following out only as it may cause you problems in the future.

If the teamone() array is dimensioned with say Dim teamone(3,3) then it is a multi-dimensional array with 16 'slots' (4x4).

In which case, putting:

teamone(1) = 5

..is not good practice as you are not providing the second element value.

Surprisingly, DBC doesn't throw a wobbler with this, but instead assumes you meant teamone(1,0).

When your arrays get bigger and more complicated, this is only going to confuse you so I suggest that you don't use the format teamone(1), but use the full version - teamone(1,0).

TDK

[href=http://www.computechtenerife.com[/href]
Southside Games
10
Years of Service
User Offline
Joined: 1st Jan 2010
Location: Don\'t tell me what to do!
Posted: 15th Apr 2012 21:17
I did not know that. I though teamone(1) was it's own slot and the other layers were added onto it. Thanks much.

Login to post a reply

Server time is: 2020-08-05 09:41:44
Your offset time is: 2020-08-05 09:41:44