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 / It says the object already exists, but I don't see how!

Author
Message
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 23rd Nov 2004 01:01
I started to create onther level to my game this morning, and after creating a few objects, I decided to try it out, I binded the up key to start level 2, and the downkey to start level 1. However, upon starting level 1, it gives me the error "object already exists" yet I cannot seem to find where in my code this error is originating. The objects I created for my second level, were from 300 to 316, I never used those numbers for any other objects, or did I? I don't know, but maybe somebody with a better eye for code can solve this mystery. Here is the code.



Even though it says to press the space key to begin, it is actually the downkey to start level 1, and the upkey to start level 2, and Level 2 is the one with the error.

Thank you.

Guns arnt the problem, people are the problem, shoot all the people and guns arnt a problem anymore.
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 23rd Nov 2004 02:10
You need to organize your code better...

It gives you the error because when it loads level 2 it returns to the loop and sees that you are still pressing down the key, then it tries to load level 2 again. However, when it loads level 1 it goes into a loop, so it does not return to the level selection screen and try to reload the level again.

You need to only have one main game loop that can handle either level, otherwise you will have a loop for each level, and your code will get too long. Firewall is over 11,000 lines long, and only has one main game loop. It even has the same loop for both the battle and arena modes, which seem very different.

You need to make it so once it loads a level in that first loop, it returns, but then uses a goto to go to the main game loop to prevent it from trying to load it again. Understand?

Xander Moser - Bolt Software - Firewall
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 23rd Nov 2004 02:21
I am not sure I understand, I know what you mean, but I don't understand how to implement it.

Guns arnt the problem, people are the problem, shoot all the people and guns arnt a problem anymore.
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 23rd Nov 2004 03:39
I will try to clarify...

This is your level 1 "subroutine":


This is your level 2 "subroutine":


As you can see, they are completely different. Your level 1 subroutine goes right into a game loop, but your level 2 subroutine returns to the game level selection loop, which, when it returns there, sees that you are still pressing the key, so it tries to load it again, giving you the error.

Here is a pseudo code thingy of what your game does:


You see what is wrong?

This is what you need to do:


Is that a little clearer?

Xander Moser - Bolt Software - Firewall
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 23rd Nov 2004 06:32
So what I should do, is have the level 2 subroutine, go directly into a loop like level 1 did? So I would need to create all the objects like I did in level 1, then create a loop to do all the collision, movement ect... and then after that loop, I use the return command?

Guns arnt the problem, people are the problem, shoot all the people and guns arnt a problem anymore.
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 23rd Nov 2004 16:06
Yes, perfect.

However, then you would have two main game loops. That is a very bad idea. Because then you would have a main game loop for each level, too many game loops. What you should do is put your main game loop in another subroutine, and gosub that subroutine after you load a level.

Xander Moser - Bolt Software - Firewall
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 24th Nov 2004 00:50
So, I create a main loop that handles all the stuff like collision, movement, ect, and then just load that Main loop for each level?

Guns arnt the problem, people are the problem, shoot all the people and guns arnt a problem anymore.
Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 24th Nov 2004 01:04
Yes, use the same main loop for every level. Just make the loading different for each level. I think you get it now.

Good Luck with your game. If you have any other similar questions, I'll be glad to help.

Xander Moser - Bolt Software - Firewall
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 24th Nov 2004 01:24
But if I was to say, put all the collision for the two levels in the main game loop, and load it for the level being played, wouldn't it return an "object doesnt exist" error, because the level wouldn't have created the objects used in the collision of both levels?

Guns arnt the problem, people are the problem, shoot all the people and guns arnt a problem anymore.

Login to post a reply

Server time is: 2025-05-24 12:53:11
Your offset time is: 2025-05-24 12:53:11