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 / Deleting objects that have already been deleted

Author
Message
Yodaman Jer
User Banned
Posted: 3rd Mar 2009 20:10
I'm having trouble deleting objects that may have already been deleted. What I mean is, if the player runs into a coin or power-up, it gets deleted. The problem is when the player loses all lives, I need a way to check and see if coins have been deleted or not. I've tried this method, which I thought would work:



But when I test it, it gives me an 'Object doesn't exist' error, because object 600 (which is one of the coins or whatnot) has been collected by the player, thus it's ALREADY been deleted.

How do I make it so that if the player loses all lives, it deletes objects that may or may not have been deleted already? If the player dies and I try to re-start the level, I of course get 'Object(s) already exist(s)' errors, because if I didn't delete certain objects, they already exist and thus the game crashes.


Does anybody have a way they use to see if objects have already been deleted?

BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 3rd Mar 2009 20:36
How about:


This even seems a bit longer than it could be, so there is probably a really cool trick you could do to just use 1 for next loop (or 2 nested loops) using arrays or something.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Yodaman Jer
User Banned
Posted: 3rd Mar 2009 20:49
That doesn't really solve my problem....

My problem is detecting if the coins or gems have already been deleted or not. You know, if the player bumps into coin 1, it gets deleted. But if the player collects other misc. coins in the level and not coin 1, then I need to see if coin 1 has been deleted or not, like so:

If object exist(600) then delete object 600

The problem is if this object HAS been deleted, then I get an error saying 'Object doesn't exist' in the 'You lose' routine.

Here's my entire code...




I dunno if that will help...? It's a really weird problem (well, maybe not ) and I thought it would work out, but it's not.

Ah well, such is programming. Thanks anyway, BN2

BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 3rd Mar 2009 21:08
Hmmm, can't figure it out, I thought if you checked if the object exists before deleting it, it wouldn't give you an error (since it doesn't exist, it just returns 0). It looks like your problem should be in that long line of delete objects that have no checks to see if they exist. Only other suggestion I have is to break the if statement like so:


Sometimes that will correct errors.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Yodaman Jer
User Banned
Posted: 3rd Mar 2009 21:34
Thanks for your help BN2, but I went with a different approach (sort of).

In the routine that creates the gems or coins I did the following:




That worked. Now the game resets itself perfectly!!

I also figured out what exactly was causing the problem...I was trying to delete and object that didn't exist. The object number '13' was a typo...hence the 'object doesn't exist error'.

So, my original idea should have worked, but because of that typo....you see what I'm getting at. I will try your other deleting technique as well, as it's much neater and slick looking. Thanks for the help!

That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 5th Mar 2009 02:38 Edited at: 5th Mar 2009 02:39
why not combine all those into this:

for x = 1 to (however many object u have)
if object exist(x)=1 then delete object x
next x

the =1 has to be there or it will give u an error i think, try it
Yodaman Jer
User Banned
Posted: 5th Mar 2009 02:49
Yeah, I'm gonna do that after I'm done experimenting.



Check out my programming blog!
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Mar 2009 10:06
Only problem with that Smart Guy is that his objects aren't all consecutive numbers, here is an idea:



Just an idea I have been working on using a nested for next loop.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 5th Mar 2009 16:59
ya but that shoudlnt be a problem cuz if the dont exist then the system wont try to delete them, the only problem i see with it being one huge loop is performance speed, having to go thru all the numbers might slow the system down
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Mar 2009 19:32
Well, there could be objects that aren't going to be deleted between some of those (if so, I would suggest re-ordering the objects for more convenience), which could present a problem.

If not, then you would be correct here smart Guy.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Yodaman Jer
User Banned
Posted: 5th Mar 2009 19:33
Quote: "ya but that shoudlnt be a problem cuz if the dont exist then the system wont try to delete them, the only problem i see with it being one huge loop is performance speed, having to go thru all the numbers might slow the system down"


You're right about the performance hit, but you're wrong about the deleting. It will be a problem if I try and delete all of those objects (even though they're not consecutive numbers) in a For...Next loop, because object numbers between 1000 and 2000 don't exist, thus I'd get an error.


Pseudo code:



That would present a problem, as the numbers aren't consecutive, as BN2 pointed out. Now, if I had every number between 1 and 3000, then it would work, but if I had that many objects on screen or used I think it would fry most computers.



Check out my programming blog!
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 5th Mar 2009 19:35
You forgot the check he put in Yodaman.

Quote: "for x = 1 to (however many object u have)
if object exist(x)=1 then delete object x
next x
"


Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Yodaman Jer
User Banned
Posted: 5th Mar 2009 19:38



I completely missed that! Forget what I said in my previous post...


Here's some coffee:



Check out my programming blog!
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 5th Mar 2009 23:04
How about you get some data



for the nums of objects that need deleteing.

Then...



~QJ
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Mar 2009 00:51
Nice quirky, I usually try to stay away from data commands (just a personal preference, no real reason), but good idea. To save space/time, I would suggest modifying it to match what I did earlier (I think I forgot to explain the numbers) where you would first put the start number, then the next number is how many consecutive numbers, so it would look like:

data 1,22,....

since you do it from 1 to 23, you read the first number, then add the second number and you have a range that you can use in for next loops. It will require more loops, but it will cut down data statements that could become cluttered and cumbersome.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 6th Mar 2009 04:30
was nething wrong with my solution, besides performance hit?
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 6th Mar 2009 08:03
Performance hit is one, but more of what I was talking about is that the range from 1 to 3000 is a BIG range, and their might be objects that he doesn't want to delete in there (for instance, 1500). If you use one blanket if->then, you would delete that object.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 6th Mar 2009 15:52
o ok i see what ur saying, maybe u could hide or ghost or do something reversible to the objects u dont want to delete, then plug in:



i think that is the right return check for ghost, check in the help to make sure
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Mar 2009 03:06
object 3000? what's wrong with object 1,2,3,4...
if you're having trouble remembering what's what just define some variables and use their names as labels: e.g.


The Universe has been erased by a mod because it was larger
than 240x80 pixels.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 8th Mar 2009 04:21
nice call, then u can use my system without the performance hit
Yodaman Jer
User Banned
Posted: 8th Mar 2009 21:48
Well guys, I actually remember what all of the objects are (3000 is a portal, 2000 is the death plain, 1000 is the skybox). I know it's really bad practice to assign such random numbers, but I am really only building a test for a game I want to make based off of my entry for NaGaCreMo. At first I thought I'd be able to complete it like it is, but now I have my doubts.


Thanks for all of the great suggestions though! I'll definitely keep them in mind for the future.



Check out my programming blog!

Login to post a reply

Server time is: 2025-05-16 07:13:41
Your offset time is: 2025-05-16 07:13:41