Hello once again,
I think my program is pretty structured, and follows the same logic as your sample state engine. I'm just using if-elsif-else instead of your using 'Select case' take a look at my 2 main functions..
REM main program loop
do
rmx= GetRawMouseX()
rmy= GetRawMouseY()
SetSpritePosition(99,rmx,rmy)
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
if rmx > 934 and rmx < 996 and rmy > 12 and rmy < 55
SetSpriteVisible(BtnExitOn,1)
buttonchoice = 1
elseif rmx > 740 and rmx < 794 and rmy > 12 and rmy < 55
SetSpriteVisible(BtnMusicOn,1)
buttonchoice = 2
elseif rmx > 804 and rmx < 924 and rmy > 12 and rmy < 55
SetSpriteVisible(BtnHowToPlayOn,1)
buttonchoice = 3
elseif rmx > 638 and rmx < 692 and rmy > 36 and rmy < 90
if gamestart = 0
SetSpriteVisible(BtnStartOn,1)
SetSpriteVisible(BtnDropOn,0)
SetSpriteVisible(BtnDropOff,0)
buttonchoice = 4
elseif gamestart = 1
SetSpriteVisible(BtnStartOn,0)
SetSpriteVisible(BtnStartOff,0)
SetSpriteVisible(BtnDropOn,1)
buttonchoice = 5
endif
else
SetSpriteVisible(BtnExitOn, 0)
SetSpriteVisible(BtnMusicOn,0)
SetSpriteVisible(BtnHowToPlayOn,0)
if gamestart = 0
SetSpriteVisible(BtnStartOn,0)
SetSpriteVisible(BtnStartOff,1)
SetSpriteVisible(BtnDropOff,0)
SetSpriteVisible(BtnDropOn,0)
elseif gamestart = 1
SetSpriteVisible(BtnStartOn,0)
SetSpriteVisible(BtnStartOff,0)
SetSpriteVisible(BtnDropOn,0)
SetSpriteVisible(BtnDropOff,1)
buttonchoice = 0
endif
endif
Sync()
if (GetPointerPressed() = 1) and buttonchoice = 1
buttonact (1)
elseif (GetPointerPressed() = 1) and buttonchoice = 2
buttonact (2)
elseif (GetPointerPressed() = 1) and buttonchoice = 3
buttonact (3)
elseif (GetPointerPressed() = 1) and buttonchoice = 4
buttonact (4)
elseif (GetPointerPressed() = 1) and buttonchoice = 5
buttonact (5)
endif
if (getrawkeyreleased(27) = 1) then exit
loop
function Buttonact ( bn as integer)
if bn = 1
SetSpriteVisible(BtnExitOn,0) `hide the Exit 'on' button
SetSpriteVisible(BtnExitPressed,1) `show the Exit button pressed
PlaySound(sound4)
Sync()
Do
if (GetPointerReleased ( ) = 1 ) then exit
if (getrawkeyreleased(27) = 1) then exit
Sync() `stay with exit button down until player releases the button
Loop
SetSpriteVisible(BtnExitOn,1) `Show the Exit 'on' button
SetSpriteVisible(BtnExitPressed,0) `Hide the Exit button pressed
PlaySound(sound5)
tx#=timer()
Repeat
SetSpritePosition(99, getRawmouseX(), getrawmousey())
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
Sync()
Until timer()-tx#>0.25
SetParticlesVisible(1,0)
End
elseif bn = 2
SetSpriteVisible(BtnMusicOn,0) `hide the Music 'on' button
SetSpriteVisible(BtnMusicPressed,1) `show the Music button pressed
PlaySound(sound4)
Sync()
Do
if (GetPointerReleased ( ) = 1 ) then exit
if (getrawkeyreleased(27) = 1) then exit
Sync() `stay with music button down until player releases the button
Loop
SetSpriteVisible(BtnMusicOn,1) `Show the Music 'on' button
SetSpriteVisible(BtnMusicPressed,0) `Hide the Music button pressed
PlaySound(sound5)
tx#=timer()
Repeat
SetSpritePosition(99, getRawmouseX(), getrawmousey())
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
Sync()
Until timer()-tx#>0.25
if musicplaying = 1
StopMusic()
musicplaying = 0
elseif musicplaying = 0
PlayMusic(Music1)
musicplaying = 1
endif
Sync()
elseif bn = 3
SetSpriteVisible(BtnHowToPlayOn,0) `hide the HowToPlay 'on' button
SetSpriteVisible(BtnHowToPlayPressed,1) `show the HowToPlay button pressed
PlaySound(sound4)
Sync()
Do
if (GetPointerReleased ( ) = 1 ) then exit
if (getrawkeyreleased(27) = 1) then exit
Sync() `stay with HowToPlay button down until player releases the button
Loop
SetSpriteVisible(BtnHowToPlayOn,1) `Show the HowToPlay 'on' button
SetSpriteVisible(BtnHowToPlayPressed,0) `Hide the HowToPlay button pressed
PlaySound(sound5)
tx#=timer()
Repeat
SetSpritePosition(99, getRawmouseX(), getrawmousey())
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
Sync()
Until timer()-tx#>0.25
`*******************
`Remember this is where the tutorial on How To Play goes
`*******************
elseif bn = 4
SetSpriteVisible(BtnStartOn,0) `hide the Start 'on' button
SetSpriteVisible(BtnStartPressed,1) `show the Start button pressed
PlaySound(sound4)
Sync()
Do
if (GetPointerReleased ( ) = 1 ) then exit
if (getrawkeyreleased(27) = 1) then exit
Sync() `stay with Start button down until player releases the button
Loop
SetSpriteVisible(BtnStartOn,1) `Show the Start 'on' button
SetSpriteVisible(BtnStartPressed,0) `Hide the Start button pressed
PlaySound(sound5)
tx#=timer()
Repeat
SetSpritePosition(99, getRawmouseX(), getrawmousey())
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
Sync()
Until timer()-tx#>0.25
SetBalls ()
resetmagnets ()
randomcolorvalues ()
shuffleboard ()
gamestart = 1
elseif bn = 5
SetSpriteVisible(BtnDropOn,0) `hide the Drop 'on' button
SetSpriteVisible(BtnDropPressed,1) `show the Drop button pressed
PlaySound(sound4)
Sync()
Do
if (GetPointerReleased ( ) = 1 ) then exit
if (getrawkeyreleased(27) = 1) then exit
Sync() `stay with Start button down until player releases the button
Loop
SetSpriteVisible(BtnDropOn,1) `Show the Drop 'on' button
SetSpriteVisible(BtnDropPressed,0) `Hide the Drop button pressed
PlaySound(sound5)
tx#=timer()
Repeat
SetSpritePosition(99, getRawmouseX(), getrawmousey())
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
Sync()
Until timer()-tx#>0.25
if ballcount > 0
dropball ()
tumbleaction()
tx#=timer()
Repeat
SetSpritePosition(99, getRawmouseX(), getrawmousey())
SetParticlesPosition(1,getRawmouseX(), getrawmousey())
Sync()
Until timer()-tx#>0.50
dropdownbonus ()
CheckBonus ()
pullupbonus ()
else
PlaySound(Buzzer, 50)
`no balls left game over
`checkhighscores ()
gamestart = 0
endif
endif
endfunction
As you can see my main loop only has a single 'Sync()' which is how the main loop should always be. in my main loop all I do is keep track of where the mouse pointer is and if it's over a 'button' I highlight that button and set the 'buttonchoice' variable to let my program know which button the cursor is over. if the pointer moves off the button the button highlight turns off..
In the next part of the main loop, I check to see if a mouse button is pressed and send the program to the buttonact () function where it handles the actions needed for each button.
The actions themselves can be as simple as exiting the program, toggling the music on/off or setting the game actions in motion and stepping through them.
Since I tend to code 'Sequentially' I add functions as needed and make sure they work before moving on. Debugging as I go type thing.. it keeps thing simple for me and for the most part I rarely run into bugs that are not related to the current function I am writing. This is the basic method I use for my programming
When I compare your 'State Machine' to my code, the only difference seems to be you like to use Case Select and I use If-Elseif-Else. As with most things in programming there are multiple ways to get the same thing done, which way is the 'Best' way is a matter of personal choice and style.
This peek into my coding process has been brought to you by "Creative Minds Use AGK" ..
Thanks for all your feedback, the bug has been fixed and the code must go on.
Cheers!