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 / AI problems for my first person shooter

Author
Message
The ARRAYinator
19
Years of Service
User Offline
Joined: 13th Aug 2005
Location:
Posted: 23rd Aug 2005 02:40
I have been trying to write a good AI program for a war kind of first person shooter were it would delete the enemy if I shot it therefore reducing the troop number. It works ok but when i delete the object after its been killed it says my object does not exist this is probaly because i have 1 subroutine for a cluster of enemies(reducing the amount of code) I will show you what i mean:

enemymovementAI:

for e=12 to 15

Point object e,X#,Y#,Z#
move object e,6

next e

return

LIke I said the game is in its early stages but I think the problem is because deleting an object in that range would make the object not exist what otherways could you do this I will include the the the main loop THANKS!!!

P.S. I deleted the delete object commands for obvious reasons but they would go under the ehealth commands.
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 23rd Aug 2005 04:32
Change it to:
for e=12 to 15
if object exist(e)
Point object e,X#,Y#,Z#
move object e,6
endif
next e
return
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 23rd Aug 2005 05:37
I'm no expert at this sort of stuff, but if I was managing a group of enemy 'objects', then I would create a numerical array - with say:

Dim Enemy(50): Rem Max number you can have
NumEnemies = 20: Rem number you want on the current level

When you create enemy number 1, then you would say Enemy(1)=1 (alive). Create number 2 and then use Enemy(2)=1. (1 = alive).

Each run through the main loop of your program, a simple for next loop would do something like:



When an enemy is killed, you delete the object and set that object's 'alive' state to 0 (dead). So if you kill object 4 then you would use Enemy(4)=0.

Once this is done, the above loop won't try to update that object's position. That's where I think your error is being caused because you are trying to move the object you just deleted.

If you want to respawn a dead enemy, or just bring in reinforcements, a similar loop would be called:



The first loop should prevent your object does not exist errors as you would only be trying to move objects which are alive - not dead.

This should work in theory.

TDK_Man

The ARRAYinator
19
Years of Service
User Offline
Joined: 13th Aug 2005
Location:
Posted: 23rd Aug 2005 17:24
Thanks TDK that works very nicely!

Login to post a reply

Server time is: 2025-05-22 13:16:38
Your offset time is: 2025-05-22 13:16:38