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 / Problem With Restarting a Program

Author
Message
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 4th Feb 2004 02:10
Ok I have made a Pong Game and i have a code here for when the games is won or lost a Message Comes up Saying If You wish To Restart or Exit. Now I dont know what is wrong with this code here please help.



Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 4th Feb 2004 05:22
i think your looking for the input command as compared to using the print command you have now.


Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 4th Feb 2004 18:37
ok i put in the input but i'm still gettin a error on this line

Quote: "if anwser$=Y then goto startofprogram"


help

Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 4th Feb 2004 18:47
Quote: "if anwser$=Y then goto startofprogram"


Try
if anwser$="Y" then goto startofprogram

Otherwise db thinks Y is a variable, enclosing it in quotes tells db it's a string value.

Our civilization faces three great dangers. The first is destruction by a nuclear war, the second is being crippled with overpopulation and the third is the Age of Leisure.
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 4th Feb 2004 19:06 Edited at: 4th Feb 2004 19:15


ok this is what i have and its still messing up now its saying no such variable! this is really a annoyin issue lol

Edit: oops On my Code i put the Variable as Anwser instead of Anwser$ but it still don work

and i'm curious is goto startofprogram even a command?

Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 4th Feb 2004 19:43 Edited at: 4th Feb 2004 19:43


something like this should get you started.

-RUST-
"What the... Mooooooooooo!"
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 4th Feb 2004 20:19
Ok this is really pissing me off now with ur code u can't see if u want to play again and what u type, also if u press Y it just stays frozen, here my Whole Code, So Hope it helps so u can help me



Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 4th Feb 2004 20:32
add SYNC after the line:

Input "You have Won! Restart, <Y or N>"; answer$

-RUST-
"What the... Mooooooooooo!"
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 4th Feb 2004 20:52
ahh still don work u try it (without the Images and Sounds of Course) and see if it works cause its driving me insane!!!! lol

Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 4th Feb 2004 20:54 Edited at: 4th Feb 2004 20:55
ok, brb

EDIT: Yikes this code is screwed up- LOL
no fear tho...
be back in a bit

-RUST-
"What the... Mooooooooooo!"
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 4th Feb 2004 21:07 Edited at: 4th Feb 2004 21:11
Ok, don't take offense. The code is a mess and I don't have time to correct it, but, I have a fully function 3d pong game that deals with all of the issues you need, so I am posting the entire code here. I suggest you use it to restructure/rewrite you code. Hope this helps you.



Edit: you can paste this code into a dbp project and run it, just rem out references to PLAY SOUND, LOAD SOUND

-RUST-
"What the... Mooooooooooo!"
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 4th Feb 2004 23:49
LOL u have DBP? i have DBC

Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Feb 2004 01:08
lol-dbp


ok, you can't run it but you can use it as a guide to structure your code into reusable subroutines and functions. Give it a go.

(ps- this is just one way of doing things, other people may do it differently.)

-RUST-
"What the... Mooooooooooo!"
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Feb 2004 01:10
also, fyi, your paddle on the left side of screen drifts back towards the center of the screen on its own without any key being pressed. You have a variable somewhere that is changing when you don't want it to (prolly a typo in the code)

-RUST-
"What the... Mooooooooooo!"
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 5th Feb 2004 04:20
Ok Thanks for your Pong Game BUT the thing is i can't understand alot of it, things like the gosub and basically your is just alot more complex

Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
John H
Retired Moderator
21
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 5th Feb 2004 04:43
Quote: "rem HIDE THE MOUSE AND LIMIT THE SYNC RATE TO 40
Sync ON : sync rate 40

rem MAKE THE PADDLES, BALL AND FLOOR
make object box 1,1,1,2:color object 1,rgb(0,255,255)
make object box 2,1,1,2:color object 2,rgb(0,255,0)
make object sphere 3,1:color object 3,rgb(255,0,0)
make object box 4,10,0.1,10:position object 4,0,-0.55,0:color object 4,rgb(255,0,255)

_initGame:
rem SET THE BALL ANGLE TO 90 DEGREES
balla#=90
rem START THE MAIN LOOP
sync on:do
rem SCORING
if ballx#>6 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=270
if ballx#<-6 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=90
set cursor 300,50:print player2score#
set cursor 320,50:print "-"
set cursor 340,50:print player1score#
Print "Created By: Bladerunner."
rem AI
if ballz#>player2pos# then player2pos#=player2pos#+0.03
if ballz#-3.5 then player1pos#=player1pos#-0.5
if upkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#+8
if downkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#-8
rem PLAYER 2 PADDLE MOVEMENT
IF keystate(17)=1 and player2pos#<3.5 then player2pos#=player2pos#+0.5
IF keystate(31)=1 and player2pos#>-3.5 then player2pos#=player2pos#-0.5
if keystate(17)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#+8
if keystate(31)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#-8
rem BOUNCING
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then Play Sound 3
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then Play Sound 3
if ballz#>4 or ballz#<-4 then balla#=180-balla#
rem MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
rem POSITION OBJECTS
position object 1,5,0,player1pos#:position object 2,-5,0,player2pos#
position object 3,ballx#,0,ballz#:yrotate object 3,balla#
position camera 0,10,-5:point camera 0,0,0
Rem Win/Lose Restart

If Player1Score#=5
cls
Input "You have Won! Restart, "; answer$
if answer$="y"
gosub _InitGame
else
end
endif
endif

sync
loop"


Well it shows up now....


We need help! Email us! join@eternaldestinyonline.com
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th Feb 2004 05:05 Edited at: 5th Feb 2004 05:14
A Tutorial for BladeRunner and whomever else may be interested!
Here, we are going to try learn how to structure and organize code

Ok, I will help try and explain it a little at a time. when you say you follow we move to the next part. Right then, so from the beginning....
Quote: "
`Global Variables
intScore1 as integer
intScore2 as integer
fltPaddleSpeed as float = .07
fltBallX as float = .05
fltBallY as float"

is just setting up some global (module global, not function global) variables for some of the main items that will be used in the game. You can see by the names that you are being told not only what the variable type is (like int for Integer) but also what the variable will hold or work with, like Score or PaddleSpeed.

this next bit touches exactly on what this thread was about...Restarting a game. Well i find it best that if you start your game the same way as you would Restart your game, you've killed two birds with one stone and have written reusable code. More of a design forethought than graceful coding (my design and my code are not the greatest in the world but I have learned a few things in my experience) Ok, so to it...
Quote: "
gosub _InitScreen
gosub _InitGameData
gosub _UpdateDisplay
gosub _EndGame
"


Gosub is nothing more than an execution directive, telling the executing assembly to "JUMP" to the label name specified in the gosub command. So the first line you see there "gosub _InitScreen" tells the program to find the label _InitScreen, do the command there until you come across a RETURN statement, which then sends execution back to the next command after the gosub statement.
Scroll down in my code and you will find the label _InitScreen. The code in that sub-routine (and that's what they are sub routines) is executed line by line until the RETURN is reached, where it then returns back to where it left off.

Look thru these sub routines and you'll see that they are used when the game first is started, and if the player chooses to restart. This is mainly what you asked about. Take the time you need and post up when you want to continue.

Your code was pretty good as far as making the ball and paddle move and stuff but it was just disorganized, or better yet it was all "in-line" which becomes kind of unreadable and is why I said it was messy.

Let me know if you'd like to continue what's becoming a code structure tutorial

Hope to help
James

-RUST-
"What the... Mooooooooooo!"
Bladerunner
21
Years of Service
User Offline
Joined: 24th Aug 2003
Location: United States
Posted: 6th Feb 2004 22:17
Ok i get what ur saying so far go on

Live as if your were to die tomorrow... Learn as if you were to live forever
Impossible is a word to be found only in the dictionary of fools
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 7th Feb 2004 00:09
Ok, well the first thing to notice is that the code that sets up the game, prior to entering the do-loop is put into subroutines. I think thats where you should start modifying your code. Things like setting up the player start positions and starting values for variables are good to have in subroutines or functions so you can call them whenever you need to (ie at the start or when the player restarts) this is what is referred to by programmers as "reusable code". Programmers try to write something once and reuse it whenever they can, not only in the current project but in other projects as well, with as little modification as possible.
So basically what we have is a bunch of routines that are called as the app starts, and then again when the game is over to allow a restart. You could take my program and strip out my code and insert your own code in the correct places. Some of the code can be left as is like the GetRandomY() function which determines the ball's up-down travel (fltBallY).

You may want try modifying your code into this basic structure and see what you can come up with. It may be easier for us both for you to point out what you don't understand as you start to build your game. One thing to note is the main game do-loop is within a subroutine itself. This is how the game restart takes place, by calling gosub MAIN from _EndGame: subroutine.

Give it a try and post your questions here and I will be more than happy to help

-RUST-
"What the... Mooooooooooo!"
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 8th Feb 2004 19:00
Hmmmmm...... that code looks familiar.




I think splitting everything up into functions will help you. It will give you a very small manageable main loop.

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Feb 2004 19:50
It's the code for my pong game, that I posted in your pong thread but then removed. Is that what you mean?

-RUST-
"What the... Mooooooooooo!"

Login to post a reply

Server time is: 2024-09-21 20:45:15
Your offset time is: 2024-09-21 20:45:15