Posted: 1st Dec 2021 7:18
So first running my game the menu starts no problem, running it with a do loop.

Then I delete everything and go to the game loop.

But when I die and loose all my lives I go back to the menu.

Everything deletes and the menu opens back up but nothing works as if I am not in the menu loop.

Somehow It does not change to go back to the menu loop it just loads in the images and other stuff.
Posted: 1st Dec 2021 8:24
I suppose if you want help you should show the code. So that other forum residents can find a bug in it. We are not psychics and cannot see the code not shown.

I myself am busy with my game.
But if your program is not complicated, then I can find time for you.
Posted: 1st Dec 2021 10:02
As pavelman said, it is impossible to help find issues with your code unless you show it.
See here for an example of how to ask for help with code.

What I can offer (if it helps) is to show you my standard game loop.
The code below (and other code irrelevant for this discussion) is automatically inserted into the main.agc file whenever I start a new project. It is my standard main game loop.
The functions are all empty and need fleshing out but it is a great starting template that might be of use to you.
+ Code Snippet
do
	StartMenu()
	repeat
		SelectLevel()
		repeat
			time = Timer()
			delta = time - lastframe
			lastframe = time
	
			GetUserInput()
			UpdatePlayer()
			UpdateEnemies()
			UpdateBullet()
			UpdateExplosions()

			levelComplete = GetLevelComplete()
			Sync()
		until levelComplete = TRUE or gameOver = TRUE
		
		if levelComplete = TRUE
			ShowLevelUpScreen()
		endif
		
	until gameOver = TRUE
	ShowGameOverScreen()
	ShowHighScoreScreen()
loop
Posted: 1st Dec 2021 10:57
This is a hat from my game that I am currently making.
+ Code Snippet
// Project: RolePlayingTacticalShooter 
// Created: 2021-11-26

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "RolePlayingTacticalShooter" )
global Height
global Width
Height=GetMAXDeviceHeight()
Width=GetMAXDeviceWidth()
SetWindowSize( Width, Height, 1)
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( Width, Height ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

Global cursor

cursor=LoadSprite( "cursor.png" )
SetSpritePosition( cursor, 0, 0 )


#include "Menu.agc"
#include "LoadMAP.agc"
#include "FPSControl.agc"

LoadMenu()


LoadMAP()
LoadSoldiers()
SetTextVisible( TextReturnButton, 0 )
for t=1 to 5
PlayObjectAnimation( qwer[t], "", 239, 261, 1, 0 ) ` move
PlayObjectAnimation( qwer[t], "", 990, 990, 1, 0 )   ` move with weapon
SetObjectAnimationSpeed( qwer[t], 20 )
next t
_Main_menu:
SetSpriteVisible ( BackDropMenu, 1 )
SetSpriteVisible ( StartButton, 1 )
SetSpriteVisible ( QuitButton, 1 )

SetTextVisible( TextQuitButton, 1 )

do
    
    SetSpritePosition( cursor, GetPointerX(), GetPointerY() )
    
    PrintMenu()
	
	printButton()
	
	if StartGame=2 then goto _Game_Loop:

    Print( ScreenFPS() )
    Print( Height )
    Print( Width )
	print ( ColorBackDrop )
	print ( PlusMinusBackDrop )
	print (StartGame)
	print (GetSpriteCollision( cursor, StartButton ))
	
	print(GetRawLastKey( )) 

	if GetRawKeyState(27) then ExitCurrentGame()

    Sync()
loop

_Game_Loop:
SetSpriteAngle( StartButton, -180)
SetSpriteVisible ( BackDropMenu, 0 )
SetSpriteVisible ( StartButton, 0 )
SetSpriteVisible ( QuitButton, 0 )

SetTextVisible( TextQuitButton, 0 )
SetTextVisible( TextStartButton, 0 )
SetTextVisible( TextReturnButton, 0 )
`SetObjectVisible( qwer1, 0 )

Do
	
	FPS()

		FPS_Soldiers()
		FPSControl()
		
 rem Update screen
 

	
	if GetRawKeyState(27) then ReturnToMenu()
	if StartGame=0 then goto _Main_menu:

 print(GetObjectAnimationTime (11))
loop


And after long torment of searching for errors, I switched to this form.
Separate cycle menu
The game is a separate cycle.
Posted: 1st Dec 2021 11:11
Wait for it.

There's a lot of GOTO haters about to jump on the thread ....
Posted: 1st Dec 2021 18:31
Hi Guys

I just noticed that if I run my menu in the main game loop and just call if menu=1 or if menu=0 then there is no problems.

Sorry to much code to show or post in this problem.

I was Gosub to the menu loop and I believe this was the problem.

There's a lot of GOTO haters about to jump on the thread


I never understood why, It is a built in function that we use for a reason, nothing wrong with GOTO .
Posted: 1st Dec 2021 20:47
"


You are correct, but the GoTo command even though it is always a part of a language, using it will cause the code to get lost. Meaning you always have to say

GoTo here:


here:

GoTo there


there:

GoTo over here

over here:
GoTo here


When you could say

GoSub here

here:
There()


Function There()

over here()
Return
EndFunction


GoTo code you will get lost and it gets messy
Posted: 1st Dec 2021 20:59
GoTo code you will get lost and it gets messy


Not unless you are using it for a good reason

If you use it correct or your program runs off of it then you should use goto

or there is gossub
Posted: 1st Dec 2021 21:09
r there is gossub


Small program you will probably not get lost, but large multi #include file programs you will probably get lost. I did
Posted: 1st Dec 2021 23:16
Here is my main game loop; Has been used since 2017 and works fabulously.
Every navigation item is an independent function that does a deletetextall() and deleteSpriteall().
Clean in and out.

GOTO's are fine until you hit a return by accident.... Your stack is now corrupted.
GOTO is a leftover from Assembler and yes, when you program an if else endif , the final machine code will still have JMP's (assembler version of GOTO).

However, it makes for code that can be a total bitch to debug when you have to. (my games typically have over 20,000 lines of code)

Good luck with your work.
James

+ Code Snippet
// ************************************************
do

	// check response
	if GetHTTPResponseReady( NU.http_id ) = YES
		response$ 							= GetHTTPResponse( NU.http_id )
	endif

	// every cycle
	AUTO__handle							()

	//
	select NU.nav_status

		case NAV__DINFO:
			DINFO__main						()
		endcase

		case NAV__CREDITS:
			CREDITS__main					()
		endcase

		case NAV__EDITOR:
			EDITOR__main					()
		endcase

		case NAV__EDSEL:
			EDSEL__main						()
		endcase

		case NAV__MENU:
			MENU__main						()
			MENU__check_purchases			()
		endcase

		case NAV__PLAY:
			PLAY__main						()
		endcase

		case NAV__SELECT:
			SELECT__main					()
		endcase

		case NAV__QUIT_APP:
			if APP.basename = "android"
				NU.mn_status				= MN__INIT
				NU.nav_status				= NAV__MENU
				MinimizeApp					()
			else
				if NU.http_id > 0
					CloseHTTPConnection	( NU.http_id )			// close web connection
					DeleteHTTPConnection	( NU.http_id )
					NU.http_id				= 0
				endif
				end
			endif
		endcase

	endselect

	sync()

loop
Posted: 2nd Dec 2021 2:42
Small program you will probably not get lost


Yes of course, I do not recommend using them for large games but for other things there good to use.

GOTO's are fine until you hit a return by accident.... Your stack is now corrupted.


Yes lol, whoops, then you spend hours and even days trying to find the problem.
Posted: 2nd Dec 2021 7:01
GOTO is sloppy, there's no need to use it. Properly structured code won't need it.
Posted: 3rd Dec 2021 4:12
nothing wrong with GOTO .


Mmmm yeah, I like a nice bolognaise ...

GoTo's invite and lead to spaghetti code if not used properly, it is a relic from 1970's and has no place in modern functional programming languages!
Posted: 3rd Dec 2021 8:45
oTo's invite and lead to spaghetti code if not used properly, it is a relic from 1970's and has no place in modern functional programming languages!


Well, as if this command is present in machine languages. It's like the foundation of the language.
Go to this address.
Without this machine code, there would be no computers that we know.

therefore you must respect and honor this command "GoTo", and you are trying to bury it.
Posted: 3rd Dec 2021 11:52
So do you have a mechanical CPU?, Did you make that post from a Turing machine?, if we are going to respect and honour tech from the past why are we using silicon and not steel?

Modernity ......

It served its place in a by-gone era but like I said "has no place in modern functional programming languages", key emphasis on the functional

I did Basic on the Atari 400 and C64 I know all about GoTo, that was 35 years ago, we have functions now ......
Posted: 3rd Dec 2021 13:41
By that logic we should all be writing code directly in binary...
Posted: 3rd Dec 2021 16:23
yes, on stone tablets