Posted: 3rd Feb 2024 1:10
How in the heck is this wrong? There should not be an error to my knowledge.
I call the function from the main file and some how it started showing this error. There is nothing but a do/loop, nothing complicated

+ Code Snippet
Function PlayerNumberSelection()
	SetScreen()
	
FileExplore.SetWindowStyle(0x10000000)

CreateText(1, "Select Number of Players")
SetTextSize(1, 25)
SetTextFont(1, 1)
SetTextColor(1, 250, 12, 0, 255)

TextW = GetTextTotalWidth(1)
SetTextPosition(1, 600 - TextW / 2, 20)

// text buttons
CreateText(2, "1")
SetTextFont(2, 1)
SetTextSize(2, 16)
SetTextColor(2, 255, 255, 255, 255)
SetTextPosition(2, 459, 323)

Acct_Num_Plyrs = 0
// main loop
do
	
	DrawBox(440, 305, 490, 355, MakeColor(220, 220, 0), MakeColor(220, 220, 0), MakeColor(220, 220, 0), MakeColor(220, 220, 0), 0)
	
	MouseX = GetPointerX()
	MouseY = GetPointerY()
		
	If GetPointerState() = 1
		If MouseX > 439 and MouseX < 491 and MouseY < 304 and MouseY < 256
			SetTextColor(2, 255, 0, 0, 255)
			Sync()
			Sleep(150)
			DeletePNS()		
			Acct_Num_Plyrs = 1
			Exit
		Endif

	Sync()

loop

EnterSurName()
EndFunction
	
Function DeletePNS()
	
	DeleteText(1)
	DeleteText(2)

EndFunction	
Posted: 3rd Feb 2024 1:21
I found the problem. 2 if/endif statements and only one endif is there. I put the other endif in and it works. Although for some reason I can't get the detection code in the main loop to work. The screen before this screen works and it has 3 areas detecting a click and all 3 work. Why won't this one work? It has same dectection code as the previous screen, just different area.
Posted: 3rd Feb 2024 2:43
You have two Mouse Y's with less than shouldn't one of these be greater than?

If MouseX > 439 and MouseX < 491 and MouseY < 304 and MouseY < 256
Posted: 3rd Feb 2024 5:09
Yes, thank you for noticing that. I changed it and it still doesn't work. I can click all day in the box and nothing happens.

Below is the function that is a screen before the above one. This one works.

+ Code Snippet
Function PlyrAccount()
	`SetScreen()
	
	FileExplore.SetWindowStyle(0x10000000) // || 0x01000000 || 0x80000000) // (WS_VISIBLE | WS_CLIPSIBLINGS | WS_POPUP)

//LoadImage(1, "GoalBall.png")
//CreateSprite(1, 1)
//SetSpriteSize(1, 1200, 431)
//SetSpritePosition(1, 0, 370)
	
	// load images
//LoadImage(2, "ManagerRed.png")   // Manager up
//LoadImage(3, "ManagerRedDark.png")   // Manager  down
//LoadImage(4,"CoachRed.png")           // coach up
//LoadImage(5,"CoachRedDark.png")    // coach down
//LoadImage(6,"LoadSavedGameRed.png")   // load saved game up
//LoadImage(7,"LoadSavedGameRedDark.png") // load saved game down


` screen title	
CreateText(0,"Select Game Type")
SetTextSize(0,25)
SetTextFont(0,1)
SetTextColor(0,250,12,0,255)
TextW=GetTextTotalWidth(0)
SetTextPosition(0,600- TextW/2,20)

//---------------------------------text above manager button -----------

` every business text
CreateText(1,"Every business")
SetTextSize(1, 12)
SetTextFont(1, 1)           // set font to use
SetTextColor(1,255, 255, 255, 255) // set text color
SetTextPosition(1,221,257)

` function controlled text
CreateText(2,"function controlled")
SetTextSize(2, 12)
SetTextFont(2,1)           // set font to use
SetTextColor(2, 255,255, 255, 255) // set text color
SetTextPosition(2,190,282)

` by player text
CreateText(3,"by player")
SetTextSize(3, 12)
SetTextFont(3,1)           // set font to use
SetTextColor(3, 255,255, 255, 255) // set text color
SetTextPosition(3,247,307)

CreateText(4, "Manager")
SetTextSize(4, 16)
SetTextFont(4, 1)
SetTextColor(4, 255, 0, 0, 255)
SetTextPosition(4, 245, 345)

`----------------------------------text above coach button
CreateText(5,"Every business")
SetTextSize(5, 12)
SetTextFont(5, 1)           // set font to use
SetTextColor(5,255, 255, 255, 255) // set text color
SetTextPosition(5,824,257)

CreateText(6,"function controlled")
SetTextSize(6, 12)
SetTextFont(6,1)           // set font to use
SetTextColor(6, 255,255, 255, 255) // set text color
SetTextPosition(6,796,282)

CreateText(7,"by computer")
SetTextSize(7, 12)
SetTextFont(7,1)           // set font to use
SetTextColor(7, 255,255, 255, 255) // set text color
SetTextPosition(7,842,307)

CreateText(8, "Coach")
SetTextSize(8, 16)
SetTextFont(8, 1)
SetTextColor(8, 255, 0, 0, 255)
SetTextPosition(8, 860, 345)

`---------------------------------------------------------------------
`----------------------------------------text above Load saved game button
` load saved game text
CreateText(9,"Load saved game")
SetTextSize(9,12)
SetTextFont(9,1)
SetTextColor(9, 255,255, 255, 255)
TextW=GetTextTotalWidth(9)
SetTextPosition(9,600-TextW/2,437)

CreateText(10,"Load saved game")
SetTextSize(10,16)
SetTextFont(10,1)
SetTextColor(10, 255,0, 0, 255)
SetTextPosition(10,505,467)

// PlyrAcct main loop
do

MouseX = GetPointerX()
MouseY = GetPointerY()

print( GameType.length)
DrawBox(1,1,1198,798,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // screen outer frame
//DrawBox(395,45,800,550,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // title frame

    DrawBox(172,341,402,364,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // Manager box
    DrawBox(775,341,1005,364,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // Coach box
    DrawBox(485,463,715,486,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0)   // Load saved game box
	
	// manager     text 10
	if GetPointerState() = 1
		if MouseX &gt; 171 and MouseX &lt;403  and MouseY &gt; 340 and MouseY &lt; 365
			SetTextColor(4, 250, 250, 250, 255)
			Sync()
			Sleep(150)
			DeleteTextObjects()
			Exit
		endif
	endif
	
	if GetPointerState() = 1
		if MouseX &gt; 775 and MouseX &lt; 1005 and MouseY &gt; 340 and MouseY &lt; 365
			SetTextColor(8, 250, 250, 250, 255)
			Sync()
			Sleep(150)
			DeleteTextObjects()
			Exit
		endif
	endif
	
	if GetPointerState() = 1
		if MouseX &gt; 485 and MouseX &lt; 715 and MouseY &gt; 463 and MouseY &lt; 486
			SetTextColor(10, 250, 250, 250, 255)
			Sync()
			Sleep(150)
			DeleteTextObjects()
			Exit
		endif
	endif	

	Sync()

loop	



PlayerNumberSelection()

EndFunction

function DeleteTextObjects()
	
		for i = 0 to 10
		DeleteText(i)
	next i

endfunction
Posted: 3rd Feb 2024 15:36
Looks like you're checking if the MouseY is less than 256 when it should be 356.

I would highly recommend turning your button code into a reusable function to avoid this kind of mistake. You could probably make it an immediate mode sort of function, like this:

+ Code Snippet
SetWindowSize(1024,768,0)
SetVirtualResolution(1024,768)
UseNewDefaultFonts(1)


while not GetRawKeyPressed(27)

    clicked = Button(400,300,600,400, 255,64,64, "Test Button")

    if clicked = 1
        print("Clicked!")
    endif

    print(ScreenFPS())
    sync()

endwhile


function Button(startX as float, startY as float, endX as float, endY as float, colorR, colorG, colorB, text as string)

  // using a temp sprite for drawing the box
  imgId = CreateImageColor(255,255,255,255)
  sprId = CreateSprite(imgId)
  SetSpriteColor(sprId, colorR, colorG, colorB, 255)
  SetSpritePosition(sprId, startX, startY)
  SetSpriteSize(sprId, endX - startX, endY - startY)

  textId = CreateText(text)
  SetTextSize(textId, 32)
  SetTextAlignment(textId, 1)
  SetTextPosition(textId, startX + (endX - startX) * 0.5, startY + (endY - startY) * 0.5 - GetTextTotalHeight(textId) * 0.5)

  mx# = GetPointerX()
  my# = GetPointerY()

  result = 0

  if mx# &gt;= startX and mx# &lt;= endX and my# &gt;= startY and my# &lt;= endY
    // add mouse-over changes here, like color change using SetSpriteColor/SetTextColor

    if GetPointerState() = 1
      // add clicked changes here

      result = 1
    endif

  endif

  DrawSprite(sprId)
  DrawText(textId)

  DeleteImage(imgId)
  DeleteSprite(sprId)
  DeleteText(textId)

endfunction result
Posted: 3rd Feb 2024 23:03
would highly recommend turning your button code into a reusable function to avoid this kind of mistake. You could probably make it an immediate mode sort of function, like this:


I corrected the MouseY coordinate code and it still doesn't work. I will try to set variables for the unfilled boxes coordinates that create the clickable button areas and see if I am smart enough to make a reusable function for multiple screens with different amounts of text objects and clickable areas

[Edit] - I just figured out that for some reason it doesn't work if you click inside box with "1" inside, but if I move the mouse up and to the left diagnally some and click it detects the click and moves on to the next screen. Why would it do that if my MouseX and MouseY coordinates are correct? (which they are correct) I verified it more than once to make sure the box coordinates were correct.

First screen code:
+ Code Snippet
// Player Account Include File
`#Include "SelectLeague.agc"

Function PlyrAccount()
	`SetScreen()
	
	FileExplore.SetWindowStyle(0x10000000) // || 0x01000000 || 0x80000000) // (WS_VISIBLE | WS_CLIPSIBLINGS | WS_POPUP)

` screen title	
CreateText(0,"Select Game Type")
SetTextSize(0,25)
SetTextFont(0,1)
SetTextColor(0,250,12,0,255)
TextW=GetTextTotalWidth(0)
SetTextPosition(0,600- TextW/2,20)

//---------------------------------text above manager button -----------

` every business text
CreateText(1,"Every business")
SetTextSize(1, 12)
SetTextFont(1, 1)           // set font to use
SetTextColor(1,255, 255, 255, 255) // set text color
SetTextPosition(1,221,257)

` function controlled text
CreateText(2,"function controlled")
SetTextSize(2, 12)
SetTextFont(2,1)           // set font to use
SetTextColor(2, 255,255, 255, 255) // set text color
SetTextPosition(2,190,282)

` by player text
CreateText(3,"by player")
SetTextSize(3, 12)
SetTextFont(3,1)           // set font to use
SetTextColor(3, 255,255, 255, 255) // set text color
SetTextPosition(3,247,307)

CreateText(4, "Manager")
SetTextSize(4, 16)
SetTextFont(4, 1)
SetTextColor(4, 255, 0, 0, 255)
SetTextPosition(4, 245, 345)

`----------------------------------text above coach button
CreateText(5,"Every business")
SetTextSize(5, 12)
SetTextFont(5, 1)           // set font to use
SetTextColor(5,255, 255, 255, 255) // set text color
SetTextPosition(5,824,257)

CreateText(6,"function controlled")
SetTextSize(6, 12)
SetTextFont(6,1)           // set font to use
SetTextColor(6, 255,255, 255, 255) // set text color
SetTextPosition(6,796,282)

CreateText(7,"by computer")
SetTextSize(7, 12)
SetTextFont(7,1)           // set font to use
SetTextColor(7, 255,255, 255, 255) // set text color
SetTextPosition(7,842,307)

CreateText(8, "Coach")
SetTextSize(8, 16)
SetTextFont(8, 1)
SetTextColor(8, 255, 0, 0, 255)
SetTextPosition(8, 860, 345)

`----------------------------------------text above Load saved game button
` load saved game text
CreateText(9,"Load saved game")
SetTextSize(9,12)
SetTextFont(9,1)
SetTextColor(9, 255,255, 255, 255)
TextW=GetTextTotalWidth(9)
SetTextPosition(9,600-TextW/2,437)

CreateText(10,"Load saved game")
SetTextSize(10,16)
SetTextFont(10,1)
SetTextColor(10, 255,0, 0, 255)
SetTextPosition(10,505,467)

// PlyrAcct main loop
do

MouseX = GetPointerX()
MouseY = GetPointerY()

print( GameType.length)
DrawBox(1,1,1198,798,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // screen outer frame
//DrawBox(395,45,800,550,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // title frame

    DrawBox(172,341,402,364,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // Manager box
    DrawBox(775,341,1005,364,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // Coach box
    DrawBox(485,463,715,486,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0)   // Load saved game box
	
	// manager     text 10
	if GetPointerState() = 1
		if MouseX &gt; 171 and MouseX &lt;403  and MouseY &gt; 340 and MouseY &lt; 365
			SetTextColor(4, 250, 250, 250, 255)
			Sync()
			Sleep(150)
			DeleteTextObjects()
			Exit
		endif
	endif
	
	if GetPointerState() = 1
		if MouseX &gt; 775 and MouseX &lt; 1005 and MouseY &gt; 340 and MouseY &lt; 365
			SetTextColor(8, 250, 250, 250, 255)
			Sync()
			Sleep(150)
			DeleteTextObjects()
			Exit
		endif
	endif
	
	if GetPointerState() = 1
		if MouseX &gt; 485 and MouseX &lt; 715 and MouseY &gt; 463 and MouseY &lt; 486
			SetTextColor(10, 250, 250, 250, 255)
			Sync()
			Sleep(150)
			DeleteTextObjects()
			Exit
		endif
	endif	
		
	Sync()

loop	


PlayerNumberSelection()

EndFunction

function DeleteTextObjects()
	
		for i = 0 to 10
		DeleteText(i)
	next i

endfunction


Second screen code that isn't working:
+ Code Snippet
// NUMBER OF PLAYERS SELECTION SCREEN FUNCTION-----------------------------------------

 Function PlayerNumberSelection()           // player number selection function
	SetScreen()
			
	WinW = GetWindowWidth()
	WinH = GetWindowHeight()
	VwinW = GetVirtualWidth()
	VwinH = GetVirtualHeight()

			
	CreateText(1, "Select number of players")        // create the screen title text
		SetTextSize(1, 25) 									// set text size
			SetTextFont(1, 1)
        SetTextColor(1, 250, 12, 0, 255)                 // set text color
	SetTextFont(1, 1)
	
	TextW = GetTextTotalWidth(1)
	SetTextPosition(1, 600-TextW/2,20)

// screen outer frame
Global LeftFramX = 1
Global RightFramX = 1198
Global TopFramY = 1
Global BottomFramY = 798

// menu frame
Global LeftMenuFramX = 490
Global RightMenuFramX = 760
Global TopMenuFramY = 292
Global BottomMenuFramY = 430
	
	CreateText(2, "1")
	SetTextFont(2, 1)
	SetTextSize(2, 16)
	SetTextColor(2, 255, 255, 255, 255)
	SetTextPosition(2, 459, 323)
	//AddVirtualButton(1, 495, 330, 50) // button 1
	//SetVirtualButtonSize(1,50,50)
	//SetVirtualButtonImageUp(1, 2)
	
	CreateText(3, "2")
	SetTextFont(3, 1)
	SetTextSize(3, 16)
	SetTextColor(3, 255, 255, 255, 255)
	SetTextPosition(3, 527, 323)	
	
    Acct_Num_Plyrs = 0

// main loop
   Repeat
		print( GameType.length)
		DrawBox(LeftFramX,TopFramY,RightFramX,BottomFramY,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // screen outer frame
		DrawBox(420,292,760,430,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // small menu frame
		
		DrawBox(440,305,490,355,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // 1 frame
		DrawBox(510,305,560,355,MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),MakeColor(220,220,0),0) // 2 frame
		
		
		// Print("Game Type : "+GameType$)
		
		MouseX = GetPointerX()
		MouseY = GetPointerY()
		
		print(MouseX)
		print(MouseY)
		
		if MouseX &lt; 439 and MouseX &lt; 491 and MouseY &lt; 304 and MouseY &lt; 356
			if GetPointerState() = 1			
				SetTextColor(2, 250, 250, 250, 255)
				Sync()
				Sleep(150)
				DeletePNS()
				Acct_Num_Plyrs = 1
				Exit
			Endif
		Endif		

		Sync()
		
	Until Acct_Num_Plyrs &gt; 0       // end loop
	
    EnterSurName()
              
EndFunction

Function DeletePNS()
	
	for t = 1 to 3
		DeleteText(t)
	next t
	
EndFunction		
Posted: 3rd Feb 2024 23:38
I corrected the MouseY coordinate code and it still doesn't work


So you changed this line:
If MouseX > 439 and MouseX < 491 and MouseY < 304 and MouseY < 256

to this:
If MouseX > 439 and MouseX < 491 and MouseY > 304 and MouseY < 356

and it still didn't work? Sorry, just making sure I'm on the same page here.
Posted: 3rd Feb 2024 23:54
nd it still didn't work? Sorry, just making sure I'm on the same page here.


That is correct, yes

I edited my previous post, the code isn't working correctly, but the code is correct and it will advance to the next screen if I click up and to the left about an inch or two. The code is correct, but why would it be doing that?
Posted: 4th Feb 2024 0:02
Ah ok, from your edited post/code:

+ Code Snippet
if MouseX &lt; 439 and MouseX &lt; 491 and MouseY &lt; 304 and MouseY &lt; 356 


You've got all less than ( < ) comparisons here. Try changing that line to this:

+ Code Snippet
if MouseX &gt; 439 and MouseX &lt; 491 and MouseY &gt; 304 and MouseY &lt; 356
Posted: 4th Feb 2024 2:39
How I kept not getting the right sign I don't know, because I could have sworn that I put the right signs in for MouseY.

I changed it to what you have in your bottom snippet.

Thank you for staying with me on that hendron. It works now