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.

Newcomers DBPro Corner / A for-loop error

Author
Message
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 21st Aug 2007 02:50 Edited at: 21st Aug 2007 02:51
I tried to use this code to make a random jumble of 50 boxes, but whenever i compile, i get and error that says "Object already exists at line 81".

Here's line 81:


Here's my code, what's wrong with it?



(p.s. Yea, i used the search button, but to no avail :'-( )

Ling creckt tsi nocreckto havela? NASA chetallnar mo lu'ul nasding!
H4ck1d
18
Years of Service
User Offline
Joined: 27th Dec 2005
Location: Yes
Posted: 21st Aug 2007 03:24
Well that error means that you already have an object for that reference number. Since your loop is from 1 to 50, if you have an object of any number between 1 and 50, this part of the program will crash. What I like to do when I need an object number is use a function like this to return the next free object number:



So if you used the function above, you could modify your current code to look like this:



Then you'll be sure that the objects you create will use an object number that hasn't been taken up already.

Hope that helped!
-H4ck1d

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 21st Aug 2007 05:21
Although in your code position object would go to the next free object that doesn't exist so it would still crash. Just make a temp variable like this:



H4ck1d
18
Years of Service
User Offline
Joined: 27th Dec 2005
Location: Yes
Posted: 21st Aug 2007 05:33
Heh woops, I was in a bit of a rush and completely missed that

Login to post a reply

Server time is: 2024-09-27 02:27:52
Your offset time is: 2024-09-27 02:27:52