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 / 65535 Objects?

Author
Message
smhillis
18
Years of Service
User Offline
Joined: 10th Oct 2006
Location:
Posted: 18th Oct 2006 03:29
If Darkbasic only allows you to make 65535 objects how can you have a weapon with infinite ammo?
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 18th Oct 2006 04:28
objects can be re-used.

imagine a machine gun firing around 20 bullets, when the bullets die its re used again.

Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 18th Oct 2006 04:31
yes, you can delete unneeded objects, like indi said, such as bullets, and objects not in view. 65535 objects isn't really a limit you should be concerned with .

Pirates of Port Royale
Live the life of a pirate.
smhillis
18
Years of Service
User Offline
Joined: 10th Oct 2006
Location:
Posted: 18th Oct 2006 05:10
I tried this code but it says object number out of range

[/while mouseclick()=1
make object sphere i,1
rem position object 1...
rem rotate object 1...
rem move object 1...
delete object i
endwhile ]

Why does this not work if I am deleting the object?
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 18th Oct 2006 07:35 Edited at: 18th Oct 2006 07:43
Also, something like a bullet is not an object in that sense until it has been "created"...by firing, for example. You can have infinite ammo...making a player have finite ammo is the trick. I think that maybe you should look at it from another angle...one that is not the player's.

Your code is trying to make an object with the object id of i, not 1...as I assume that you intended. I think you have the parameters to the make object sphere reversed. Try it like this:

make object sphere 1, 1.0

That creates an object with an ID of 1, and a radius of 1.0. Your code will work then. I assume that i = 0...and object 0 does not exist...ever. Particularly when deleting, you might want to check to see if an object with that ID exists first.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Oct 2006 11:01
Quote: "Why does this not work if I am deleting the object? "


Because i is either 0 or a number which is too large.

But your code won't do anything useful in any case. It will only ever be in one position, before it is deleted and recreated in the same position.

Bullets don't actually have to exist. Because of their speed, it is most likely that they will "miss" their target. In one cycle they will be in front, and the next they will be behind. The normal method for bullets is to raycast from the weapon to the target, to see if it will collide.

Slower weapons, such as an arrow or a rocket would be represented by an object. In this case, you need to consider using an array of reusable objects, as already mentioned.



The admiral
22
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 18th Oct 2006 11:30
Yup raycasting is the way its done these days and even if you wanted unlimited bullet objects the memory limitations would slow down your game until it crashed.

The admiral
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 20th Oct 2006 10:48
What is raycasting?

And it can be done with object, if you use a function that moves the object one step at a time, and check if it collides with a target. If it does, you exit the loop and the function returns a one, else it jumps out of the loop when the bullet has moved as far as it should and the function returns a zero. Don't know if this is better then raycasting, since I don't know what that is.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Oct 2006 11:56
If your bullet moves 10 units per cycle, and your object is 5 units deep, there is a good chance the bullet will pass straight through without colliding.

Raycasting draws a line between the start point and end point, and checks if this line collides with any objects. So even if you have an object as your missile you should raycast anyway if there is any chance it will pass straight through.



smhillis
18
Years of Service
User Offline
Joined: 10th Oct 2006
Location:
Posted: 21st Oct 2006 21:18
But what if you DID want to see every single bullet fired? Which is what I'm trying to do.

Also, the problem I have with using the same object is the fact that really there is only one object on screen at one time. You have to wait for that bullet to disappear before another bullet fires.

I thought making an array of say 100 bullet objects and then when the user has fired them all just add another 100 bullets to the array.

But isnt this a drawback of the array data type? Arrays cannot be added to. Would it be possible to create something like a linked list? Then you just insert another bullet right behind the one that was just fired in the list.
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 22nd Oct 2006 21:12 Edited at: 22nd Oct 2006 21:23
Then you would detect the condition of firing in your game loop...probably tied to a keystroke, or mouseclick event....and you would create a terribly small rectangle object, which would "live" until something was hit, or it could ricochet...anyway, you would kill it eventually with delete object. You would not need to wait if you were using a different object ID for each bullet. You need a system that will give you an unique object ID for each bullet. Others have posted this before, but I use a function that will give you a valid ID each time you use it. You will need to save the object ID of each bullet in order to know which ID to delete. Clear as mud, huh?



You give the code a place to start, and it will return the first available object ID.

Your bullet array is a great idea...but, like I said, you don't need to use a DBPro asset (object id) until you want to place a bullet on the screen. In your bullet array, use -1 for the ID when the bullets are "in the chamber", and grab an ID when you fire them. Making the object does not really take very long, especially for primitives that are created programmatically, as opposed to being loaded from a file.

DBPro uses a similar method to C++'s template for stacks....you can use stacks for what you want....they are similar to linked lists in that respect...you can add and remove at your leisure.
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 23rd Oct 2006 02:04 Edited at: 23rd Oct 2006 22:15
Here's the method I'm using for my Asteroids game.



First, make a bullet type, then dim an empty array. Whenever you want to make a bullet, add an array slot, set the life to default, and put the value from a free_obj() function in the id field. The code I posted loops through each bullet, decrements it's life, moves it, and if its life has run out, delete it.

[edit]

Oops... Thought this was about Pro.

Confucius Say...
smhillis
18
Years of Service
User Offline
Joined: 10th Oct 2006
Location:
Posted: 24th Oct 2006 05:07
Thank you for the help , though it looks like all of the source is in Pro and I'm just using classic. I think I will just upgrade at this point as it looks like Pro will give me a little more power to do the things I need.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 25th Oct 2006 00:24
You'll be much happier with Pro. Its faster and has a lot more commands.

Login to post a reply

Server time is: 2024-11-26 07:30:41
Your offset time is: 2024-11-26 07:30:41