• Welcome to Dark Bit Factory & Gravity.
 

Goto routines . . .

Started by DrewPee, June 13, 2009

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DrewPee

Hello
I am in the process of writing a very basic game to test some drawing routines I am messing about with . . . I am stuck with re-starting a game once you die.
Do I need to use something like a goto command or is there something else I can use in Freebasic?

When I try to use goto I keep on getting this error

94: Branching to other functions or to module-level, to label: strt

Thanks in anticipation

DrewPee

DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

There's no need to use commands like Goto nowadays Drewpee.

You could structure your game code something like this;


QUIT  = 0
GAME = 0

MAIN LOOP (LOOPS UNTIL QUIT=1)
    IF QUIT = 0 THEN HANDLE TITLE SCREEN SUB
    IF GAME=1 THEN HANDLE GAME SUB
END OF MAIN LOOP

END PROGRAM


HANDLE GAME SUB
START OF LOOP UNTIL GAME=0
   CALL GAME SUBS
   UPDATE SCREEN
   IF DEAD THEN GAME=0
END OF LOOP UNTIL GAME=0
END OF HANDLE GAME SUB



HANDLE TITLE SCREEN SUB
START OF LOOP UNTIL GAME=1
   CALL TITLE SCREEN SUBS
   UPDATE SCREEN
   IF START BUTTON PRESSED THEN GAME=1
   IF QUIT BUTTON PRESSED THEN QUIT=1
END OF LOOP UNTIL GAME=1 OR QUIT=1
END OF HANDLE TITLE SCREEN SUB

Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

#2
Shockwave, thanks (as always for your help!),

code removed for now - due to odd problems with some of it - I will re-post at a later date ;)

DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

DrewPee

#3
Meant to say - this is still early code so there are bits in there that are not needed etc. ;)
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

You need to understand what happens to the stack.

You branch to a sub and the memory address is stored
when the end sub is encountered, you go back to that last address.

Using goto the way you have in a sub potentially could cause a stack overflow which is why it's terrible programming practice and why freebasic wont let you do it.

The technique I posted is very simple to impliment, why not have a try yourself and post back if you run into problems.

Seriously, forget about goto, there is no need to use it... ever.
Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

Thanks Shockwave I will go and try it again.
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

I have figured it out a little more and this is where I am at the moment - still early days but playable now! ;)

@Shockwave - thanks again for your help!

btw - the highest score so far is 2392, not by me I might add, by one of our members on RCM!

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

It looks pretty cool indeed :)

The only flaw I can see is the method you used to detect your keypresses causes a delay in movement...

Use this method instead..

IF GETASYNCKEYSTATE( VK_UP ) Then do stuff.

:)

Shockwave ^ Codigos
Challenge Trophies Won:

Hotshot

very good.....Original game

GOTO is horrible but have you thought about using Select case?

Shockwave

Select Case will not help here Hotshot, you'd use Selest Case the same as switch or if and then.

He just needs to have some controling subs and a containing loop.
Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

I am still 'cheating' a little - but it does work much better now . . . I have added some music, difficulty levels etc.

.exe attached
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

Still has the slightly annoying movement delay when pressing a key (see above for the solution) but apart from that it's not bad at all.

It's great to see you doing some programming again Drewpee, you should do more but I guess that it's hard to get the time these days.
Shockwave ^ Codigos
Challenge Trophies Won:

DrewPee

I am using the commands you mentioned, I think I just have them in the wrong place - need to move the code around a little me thinks! ;)
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Shockwave

You should use GETASYNCKEYSTATE
Like this:

IF GETASYNCKEYSTATE( VK_UP ) THEN

(without the =-32768 bit), that why the controls are slightly broken atm.
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

If you are going the Select Case route, if you use Select Case As Const Choice

Choice being a variable of your choice ( hehe, get it ) it's apparently better / faster.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: