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 / trying to setup code to switch camera position

Author
Message
Cronius Draks
15
Years of Service
User Offline
Joined: 8th Dec 2008
Location:
Posted: 13th Dec 2008 22:07
I can set GameMode$ to be "BattleField" or "Bunker" before i get to the mainloop and it uses that path each cycle just fine. but when I try to switch between the two it just stays in that mode. I have an object that is moved and turned each cycle so I know its going into the appropriate branch correctly each cycle and i can sit there and watch it go in circles, it just never switches to the other branch.

I have tried printing the value of switchmode on the screen to see if it just was never getting to 300 but it increments each cycle as it should, it just never triggers the switch.

my brain is fried over this. I look at this code and I just don't get why its not working.

I am assuming i dont have something setup right, any clues?

rem Main loop
while ProgramRunning=1

move object 1001,1
turn object left 1001,1

SwitchMode=SwitchMode+1
if SwitchMode>300 and GameMode$="Bunker" then GameMode$="BattleField":SwitchMode=0:Gosub GameModeBattleField
if SwitchMode>300 and GameMode$="BattleField" then GameMode$="Bunker":SwitchMode=0:Gosub GameModeBunker

If GameMode$="Bunker" then Gosub GameModeBunker
if GameMode$="Battlefield" then Gosub GameModeBattlefield

Wandering the digital world in search of knowledge for 22 years... you would think I might have found something useful by now.
BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 14th Dec 2008 05:36 Edited at: 14th Dec 2008 05:37
Your problem is that your second if statement will instantly change GameMode$ back to Bunker. I would suggest changing it all to a case select so once it switches the GameMode, it won't run the other line of code.

Something like-



Not sure if that's right, I'm tired and typed that up quickly.
Cronius Draks
15
Years of Service
User Offline
Joined: 8th Dec 2008
Location:
Posted: 14th Dec 2008 06:09
ok, i currently have it setup like this, and it works fine. when i hold down the space key, the view changes to the bunker view and I can move the camera around.


make camera 1

rem*******************************************************************************************************
rem Main loop
Do

move object 1001,1
turn object left 1001,1

if spacekey()=1
position camera 1,512,-1000,512
else
position camera 1,512,20,450
endif

if mouseclick()=2 then CameraRotationY=CameraRotationY+mousemovex()
if mouseclick()=2 then CameraRotationX=CameraRotationX+mousemovey()

mousemovex()=0
mousemovey()=0
RotateCameraY=CameraRotationY/4
RotateCameraX=CameraRotationX/4
Yrotate camera 1,RotateCameraY
Xrotate camera 1,RotateCameraX



but if i move the camera position and camera movement to the two subroutines, and put gosub statements in the if else then it will go to the default view and never switch back with the space key. do gosub statement not work like this in if else statements?

the program will have extensive differences in the two views and I cant imagine leaving everything bunched together in the main loop.

Wandering the digital world in search of knowledge for 22 years... you would think I might have found something useful by now.
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 15th Dec 2008 22:54
Gosub should work there. Are you putting a return at the end of your subroutine?
Cronius Draks
15
Years of Service
User Offline
Joined: 8th Dec 2008
Location:
Posted: 16th Dec 2008 03:22
I resolved this problem for a while, then i tried getting fancy and tried setting up a menu using sprites. I think my problem now is in the sprite collision though.

I noticed the test doesn't write on top of the sprites unless i use paste sprite in place of these sprite statements. neither way seems to work with collision though. as far as i can tell I am doing what needs to be done but clearly i have done something wrong.

[/code]
UseMainMenu:
if spacekey()=1 then CloseMainMenu=CloseMainMenu+1
if CloseMainMenu=30
CloseMainMenu=0
MainMenuActive=0
Endif

sprite 2,350,30,101
sprite 3,405,75,102
sprite 4,405,115,102
sprite 5,405,195,102
sprite 6,405,265,102
sprite 7,405,335,102
sprite 8,405,405,102
sprite 1,mousex(),mousey(),103
if GameMode$="Bunker" then GameModeSwitch$="BATTLEFIELD"
if GameMode$="Battlefield" then GameModeSwitch$="BUNKER"

center text 477,72,"NEW GAME"
center text 477,142,"LOAD GAME"
center text 477,212,"SAVE GAME"
center text 477,292,GameModeSwitch$
center text 477,362,"DESIGN"
center text 477,432,"QUIT GAME"

if mouseclick()=1
GameModeClicked=sprite collision(1,6)
QuitGameClicked=sprite collision(1,8)
if GameModeClicked=1
GameModeClickedDetector=GameModeClickedDetector+1
GameModeClicked=0
MainMenuActive=0
Select GameMode$:
Case "Bunker"
GameMode$="Battlefield"
Endcase
Case "Battlefield"
GameMode$="Bunker"
Endcase
Endselect
Endif
if QuitGameClicked=1
QuitGameClicked=0
MainMenuActive=0
Exit
Endif
Endif
return[code]

Wandering the digital world in search of knowledge for 22 years... you would think I might have found something useful by now.
Cronius Draks
15
Years of Service
User Offline
Joined: 8th Dec 2008
Location:
Posted: 16th Dec 2008 04:17
Well I managed to get it working. switched it back to pasted sprites and it worked. guess I had something type wrong before.

ok... now on to the juicy stuff. gotta figure out parsing strings so I can implement an AI scripting capability.

thanks for the help.


<Rides off into the sunset>
well I guess its too late for that...

<Rides off into the cold starry night>

Wandering the digital world in search of knowledge for 22 years... you would think I might have found something useful by now.

Login to post a reply

Server time is: 2024-09-27 22:29:58
Your offset time is: 2024-09-27 22:29:58