Posted: 16th Jan 2022 7:17
Hi,

I have 2 menu screens that appear one after the other. They both use 1024x768 window and the same formula to place text in the center up top of the screen. It should work, but it doesn't in the 2nd menu, it appears far left. Why?
All functions here are called in order in the main game engine loop code file. So it goes from one menu to the next. Each menu code is in their respective #include file
All variables are declared global in the main game engine code file near the top

The formula in question is
+ Code Snippet
SetTextPosition(1, VwinW / 2 - TextW / 2, 50)


First menu
+ Code Snippet
Function PlayerNumberSelection()           // PLAYER NUMBER SELECTION SCREEN FUNCTION START
	SetScreen()
	
	VwinW = GetVirtualWidth()
	VwinH = GetVirtualHeight()
	
	LoadImageResized(1, "football.png", 0.5, 1.0, 0)                     // load background image
	   CreateSprite(1, 1)   
	   SetSpriteSize(1, 1024, 768)
	SetSpritePosition(1, 0, 0)                                                   // set background sprite postion
			
	CreateText(1, "SELECT NUMBER OF PLAYERS")           // create the text used at the top of the menu
	   SetTextSize(1, 70)                                                      // set text size
	   SetTextBold(1, 1)                                                       // set text to bold
	SetTextColor(1, 250, 250, 0, 255)                                // set text color

	TextW = GetTextTotalWidth(1)
	SetTextPosition(1, VwinW / 2 - TextW / 2, 50)
	
Timer# = Timer()                                              // set timer variable
        Repeat                                                        // start repeat until loop
			MouseLocation()
			Sync()                                     // sync or refresh the screen
        Until Timer# + 5 <= Timer()              // end of the repeat until loop

      DeleteText(1)
      DeleteImage(1)
      DeleteSprite(1)

      ClearScreen()
EndFunction

Function MouseLocation()
	
      OldMouseX = MouseX
      OldMouseY = MouseY
      MouseX = GetRawMouseX()
      MouseY = GetRawMouseY()
      PrintC("MouseX ") : Print(MouseX)
      PrintC("MouseY ") : Print(MouseY)
      
ResetTimer()

EndFunction


Second menu
+ Code Snippet
Function TeamRoster()
    
    SetScreen()
	LoadImageResized(1, "football.png", 0.5, 1.0, 0)                     // LOAD MENU BACKGROUND
		CreateSprite(1, 1)  
		SetSpriteSize(1, 1024, 768)                                              // CREATE A SPRITE TO SHOW ON SCREEN
	SetSpritePosition(1, 0, 0)                                                         // SET THE POSITION OF THE SPRITE

	CreateText(1, "TEAM ROSTER")                                                  // MENU TITLE
		SetTextSize(1, 50)                                                                  // SET THE TITLE TEXT SIZE
			SetTextColor(1, 0, 0, 0, 255)                                             // SET THE TITLE TEXT COLOR
			SetTextBold(1, 1)                                                         // SET TEXT TO BOLD
		TextW = GetTextTotalWidth(1)                                             // GET TOTAL WIDTH OF THE TEXT OBJECT
	 SetTextPosition(1, VwinW / 2 - TextW / 2, 20)                                     // FIND LOCATION ON SCREEN TO POSITION TEXT AND PLACE IT

// TEMPORARY TIMER JUST TO SET MENUS UP. WE NEED TO REPLACE WITH PROPER INPUT DETECTION
	Timer# = Timer()
	Repeat
		
	    Sync()
	Until Timer# + 10 <= Timer()
	
	ResetTimer()
	
	DeleteText(1)		
	DeleteSprite(1)
	DeleteImage(1)
		
EndFunction
Posted: 16th Jan 2022 9:34
My guess is that you haven't set VwinW as global. So in your TeamRoster() function it is zero
Posted: 16th Jan 2022 15:26
My guess is that you haven't set VwinW as global. So in your TeamRoster() function it is zero


Yes, near the top of the main code file VwinW is declared Global

+ Code Snippet
// INTRO SCREEN MENUS INCLUDES IN ORDER OF USE
#Include "DisplaySettings.agc"
#Include "SplashScreen.agc"
#Include "PlayerNumberSelection.agc"
#Include "EnterSirName.agc"
#Include "SelectLeague.agc"
#Include "SelectTeam.agc"
#Include "DifficultyLevel.agc"

// ALL INCLUDES USED DURING GAME PLAY
#Include "FootballField.agc"

`#Include "AgentAI.agc"
`#Include "CoachesAI.agc"
`#Include "Consessions.agc"
`#Include "ManagerAI.agc"
`#Include "PlayerAI.agc"
`#Include "PlayerTrade.agc"
`#Include "PlayerTraining.agc"
`#Include "RefereeAI.agc"
`#Include "ShortList.agc"
`#Include "StadiumGrounds.agc"
`#Include "TeamFinancial.agc"
`#Include "TeamFormations.agc"
#Include "TeamRoster.agc"
`#Include "TeamTalk.agc"
`#Include "TeamTraining.agc"

`#Include "CameraFly.agc"

SetErrorMode(2)


SetOrientationAllowed(0, 0, 1, 0)
SetSyncRate(60, 0)
SetErrorMode(2)

Global SBL, SBT, SBR, SBB         // SBL = screen bounds left / SBT = screen bounds top / SBR = screen bounds right / SBB = screen bounds bottom
Global DeviceW, DeviceH                
Global MdeviceW, MdeviceH
Global VwinW, VwinH


The 2 menu's #Include files are listed there too and they are both obviously not remmed out lol
Posted: 16th Jan 2022 15:43
For some weird reason it it working now. Maybe since I had been working on the game for a long time yesterday I just needed to clear the memory of AGK. I started it up this morning and it worked. Hmm
Posted: 16th Jan 2022 16:30
Something weird hmm, The formula works only if both menus are running one after the other, but if I rem out the function call in main code file to the PlayerNumerSelection() then the TeamRoster menu running by itself shows "Team Roster" to the far left. I uploaded a screen shot. Just disreguard all the buttons and other text in the upper left of screen they aren't relevent to the issue. They are there because I use to run the program in 1920x1080 and I'm currently relocating everything for 1024x768
Posted: 16th Jan 2022 17:06
instead of doing this:
+ Code Snippet
TextW = GetTextTotalWidth(1)                                             // GET TOTAL WIDTH OF THE TEXT OBJECT
     SetTextPosition(1, VwinW / 2 - TextW / 2, 20) 

It would be easier to place the text in the centre of the screen and centre align the text. Like this:
+ Code Snippet
SetTextAlignment(1, 1)
SetTextPosition(1, 512, 20) // Or VwinW / 2 instead of 512 if you plan to change the screen dimension later


Also, are you aware that you are using the same ID for both text objects?
Posted: 16th Jan 2022 18:05
Yes, I agree that it would be easier to do as you have suggested. I tried it and it worked before I even started this thread, but I was just trying to set things to variables to allow the screen resolution to be changed in game settings if someone wanted to.

lso, are you aware that you are using the same ID for both text objects?


Yes, I'm aware that I am using the same ID for both text objects, but at the end of each menu I have it deleting everything including the text objects before it goes to the next menu so the ID should be freed up correct?
Posted: 16th Jan 2022 18:07
You're assigning VwinW and VwinH in your PlayerNumberSelection() function but not in your TeamRoster() function
Posted: 16th Jan 2022 18:36
You're assigning VwinW and VwinH in your PlayerNumberSelection() function but not in your TeamRoster() function


Thank you hendron, I didn't know I had to do it for both menus. Maybe I thought since it already was set before TeamRoster() menu that it would adust for the TeamRoster menu because of different text object length.

Thank you that worked. Now I can continue to set the rest of the menu up and not have to run anything but TeamRoster menu so I don't have to wait through previous menus to get to the TeamRoster.
Posted: 17th Jan 2022 19:30
Thank you hendron, I didn't know I had to do it for both menus. Maybe I thought since it already was set before TeamRoster() menu that it would adust for the TeamRoster menu because of different text object length.


No problem. You were getting the inconsistency you mentioned because if you didn't call PlayerNumberSelection() before TeamRoster(), then VwinW and VwinH were never being set. Personally I would recommend setting the VwinW and VwinH variables once, outside of either of those functions, before they are called.