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 / Wont create another object??? ...... AAAAARRRRRGGGG!!!!!! (help!)

Author
Message
Starsu
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location:
Posted: 19th Oct 2003 07:19
Okey dokey. Now, this is driving me insane. Here is what my problem is. Im working on an asteroids style game. I havent done all that much on it... mainly, just got the ship moving correctly and stuff, which works just fine. Now. I want the ship to, of course, shoot stuff. So I go to create a bullet. Simple, done it before. But.... it refuses to do it? It says "object already exists", and then it highlights a line that says... "loop"? ... huh? At this point, there only is ONE object... the players ship. It's the only thing there so far. and yes I made sure Im not using the same object number as that ship. So why in the hippidy hop does this refuse to work? Here is the code as it exists:

sync on
dim playerbullet(4)
dim playerbulletx(4)
dim playerbullety(4)
dim playerbulletang(4)
remstart
OBJECT NUMBER INFO
1=player ship
2-6=player bullets

remend


load sound "phaser.wav", 1
load object "spcveh16.x",1
zrotate object 1,180
xrotate object 1,90

position object 1, 0,0,200
position camera 0,100,0


rem position ship in center of screen
x#=0:y#=0
position object 1,x#,y#,200
id=1
moveDist#=0.065
friction#=0.97

rem main loop
do

xPos#=object position x(1)
yPos#=object position y(1)
zAng#=object angle y(1)
`apply forward movement
if upkey()=1
xSpeed#=xSpeed#+newxvalue(0,zAng#+180,moveDist#)
ySpeed#=ySpeed#+newzvalue(0,zAng#+180,moveDist#)
endif

`apply backward movement
remstart
if =1
xSpeed#=xSpeed#+newxvalue(0,zAng#,moveDist#*-1)
zSpeed#=zSpeed#+newzvalue(0,zAng#,moveDist#*-1)
endif
remend
`apply left rotation
if leftkey()=1
yrotate object 1,wrapvalue(zAng#+4)
endif

`apply right rotation
if rightkey()=1
yrotate object 1,wrapvalue(zAng#-4)
endif

`shoot stuff!
if shiftkey()=1
gosub playershot
endif

`friction!

`work out value with friction
xSpeed#=xSpeed#*friction#
ySpeed#=ySpeed#*friction#

`work out the new position
xPos#=xPos#+xSpeed#
yPos#=yPos#-ySpeed#



rem if ship leaves the screen it will appear on the other side
if xpos# <-180 then xpos#=180
if xpos# >180 then xpos#=-180
if ypos# <-130 then ypos#=180
if ypos# >180 then ypos#=-130
position object 1,xPos#,yPos#,200
sync
loop

playershot:
rem find an available bullet spot. If one doesnt exist, simply return to main loop
yy=0
monkeyshine:
if playerbullet(yy)=0 then goto plcreate
yy=yy+1
if yy=5 then return
goto monkeyshine
playerbullet(yy)=1
plcreate:

rem get the position and angle of main ship
shotang#=object angle y(1)
shotxpos#=object position x(1)
shotypos#=object position y(1)

rem create shot, position on ship, and point in same direction as ship
make object sphere yy+25,5
position object yy+25,shotxpos#,shotypos#,200
set object to object orientation yy+25,1
return



there it is. Now, Im sure it's probably just something really really stupid... some hideously dumb bug that Im overlooking repeatedly (as happens frequently when Im makin something). But I cant find it. And it is driving me nuts. And the fact that it thinks the LOOP command is the problem isnt helping. Also, keep in mind I have DB, not DBpro. Please help!
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 19th Oct 2003 09:08
make object ObjectNumber
make sprite SpriteNumber
make sound SoundNumber

make smell SmellNumber - oops thats not in the commands





You have to manage the media numbers as well as deleting them when the time comes for you to end the game or restart a level.


take a pen and paper (eww thats like a book!) and write down all the objects you will need, then assign each one a unique number.


PlayerObject -- object 1
EnemyObject -- object 2

BulletObject 1 -- object 3
BulletObject 2 -- object 4


Do it for 2d images /3d objects/sounds/music and most things you want to keep track of.

You can make life simpler for yourself also and reference a variable as your number.


EG:

PlayerOBJ = 1
PlayerOBJSize = 10
make object cube PlayerOBJ,PlayerOBJSize


now whenever you want to reference player ones 3d object you would use the varaible name PlayerOBJ.
if you continue to do that through out your code then to change the players 3d media location you just alter the variables data which in this case is the 1.


EG:

PlayerOBJ = 5
rem now the player will be referenced through your code as media 5 location.


This is a very basic method and perhaps you should explore assigning an array so this variable of PlayerOBJ is global across a function or a Typed Array Like Player(1).OBJ

Starsu
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location:
Posted: 19th Oct 2003 18:55
Hmmm.... I still cant get this to work. and I DONT KNOW WHY. After going over what you said, I went and very very carefully checked the object numbers in the program, making sure I wasnt duplicating something. Down where it says "make object sphere", I tried changing that to various numbers that should have made it impossible to screw up. But even if I change it to something like 2053, it still decides that there is already an object there. There must be something else going on.... but what? Help again!!!!!
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 19th Oct 2003 22:04 Edited at: 20th Oct 2003 06:05
You check for existance here...

if playerbullet(yy)=0 then goto plcreate

But, where do you set playerbullet(YY)? It should be in the plcreate routine.
--
TAZ


I put this loop in front of your main sync to animate the bullets...

At some point you'll have to add a collision check and bullet expire time. Also, instead of using 1 for the bullet movement some frame independent code would be good. Something like (10/screen fps()) will do. With 10 being some constant speed you want per second.

In the plcreate routine I added...

playerbullet(yy) = 1
[edit] I placed this line right before the return after the sphere is made.

I hope that gets you back in the saddle on your project.
--
TAZ
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 19th Oct 2003 23:01
playershot:
rem find an available bullet spot. If one doesnt exist, simply return to main loop
yy=0<<<<<<<<<<<HERE YY IS MADE TO EQUAL 0
monkeyshine:
if playerbullet(yy)=0 then goto plcreate<<<<<<<<<SO YOU ALWAYS GO TO PLCREATE
yy=yy+1<<<<<<<<<<<<HERE YOU ADD ONE TO YY...BUT NEXT TIME YOU CALL THE FUNCTION YOU WILL RESET IT TO ZERO ON THE LINE YY=0
if yy=5 then return<<<<<<<<<SO YY NEVER=5
goto monkeyshine<<<<<<SO YOU GO TO MONKEYSHINE AND THEN CAN`T GO TO PLCREATE SINCE YY IS NOT EQUAL TO 0
playerbullet(yy)=1<<<<<<<<THEN YOU SET YY TO 1 (WHY?)
plcreate:

rem get the position and angle of main ship
shotang#=object angle y(1)
shotxpos#=object position x(1)
shotypos#=object position y(1)

rem create shot, position on ship, and point in same direction as ship
make object sphere yy+25,5<<<<<<<<SO OBJECT NUMBER IS ALWAYS 25 (0+25)
position object yy+25,shotxpos#,shotypos#,200
set object to object orientation yy+25,1
return<<<<<<<<<<<<<<<<<<AND YOU RETURN

I did a lenthy explanation on multiple bullets somewhere on this forum and several others have too, try searching for an example of the methods used for multiple bullets, cheers.

Mentor.
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 20th Oct 2003 06:18 Edited at: 20th Oct 2003 06:28
Mentor, I think you're looking at the code the wrong way. The monkeyshine logic merely loops through the five bullet slots and looks to see any of them are not in use. If all five bullets are in play, the routine exits. If an open slot is found, plcreate is called and a new bullet in made. The bug was that "playerbullet(yy) = 1" was above the plcreate label and was thus never called.

Starsu's code should work with the fixes that I mentioned. The important next step for him is to make sure that the bullets 'expire' and the bullet slots are set back to zero. Otherwise, he'll never get to fire more than five bullets.

Thoughts on bullet expiring: Of course, if they hit something during the collision check they should expire. You can also add an element to the bullet array to hold either time or distance values. I think distance would be easier to code. Something like this after the move object command...

--
TAZ
GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 20th Oct 2003 17:54
an easy way to have it select the line of code thats not working is to take off all the sync commands, run it, get the error message and it will highlight the bad line of code (or sometimes the one before or after) then, fix the line... re add all your sync commands then it should run...well...hope this helps...

If It Wern't For Bad Apples, Good Apples Would Only Be Average...

Login to post a reply

Server time is: 2024-09-21 05:38:36
Your offset time is: 2024-09-21 05:38:36