i think you're wanting more of a toggle switch function than a Virtual Button. but, you're swapping 1 image for another and not both?
i'm obviously not following completely, and this isnt as perfect as i'd like, but might help:
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "buts" )
SetWindowSize( 640,360, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 640,360 )
SetOrientationAllowed( 1, 1, 1, 1 ) // portrait, portrait2, landscape, landscape2
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
CenterWindow()
GLOBAL OnIMG, OffIMG
MakeIMGS()
Type Butn
ID, WasPressed, State
EndType
GLOBAL Buttons as Butn []
AddButtons(34)
do
Print( CheckButtons() )
Print("Total: " + STR(Buttons.Length) )
Sync()
loop
Function CheckButtons()
Status$ = ""
For x = 0 To Buttons.Length
If GetVirtualButtonReleased(Buttons[x].ID) and Buttons[x].WasPressed = 0
Buttons[x].WasPressed = 1
If Buttons[x].State = 1 then Buttons[x].State = 0 Else Buttons[x].State = 1
If Buttons[x].State = 1
SetVirtualButtonImageDown(Buttons[x].ID, OffIMG)
SetVirtualButtonImageUp(Buttons[x].ID, OnIMG)
Else
SetVirtualButtonImageDown(Buttons[x].ID, OnIMG)
SetVirtualButtonImageUp(Buttons[x].ID, OffIMG)
EndIf
Else
Buttons[x].WasPressed = 0
EndIf
Status$ = Status$ + STR(Buttons[x].State)
Next x
EndFunction Status$
Function AddButtons(num)
ThisButn as Butn
ButNum = 1
For x = 1 to num
While GetVirtualButtonExists(ButNum)
INC ButNum
EndWhile
ThisButn.ID = ButNum
TotalButs = Buttons.Length + 1
ThisY = 68+FLOOR(TotalButs/10)*34
ThisX = 17+MOD(TotalButs,10)*34
AddVirtualButton(ButNum, ThisX, ThisY, 32)
ThisButn.State = 1
SetVirtualButtonImageDown(ButNum,OffIMG)
SetVirtualButtonImageUp(ButNum,OnIMG)
Buttons.Insert(ThisButn)
Next x
Endfunction
Function MakeIMGS()
AddVirtualButton(1,16,16,32)
SetVirtualButtonColor(1,0,255,0)
Render() : OnIMG = GetImage(0,0,32,32)
SetVirtualButtonColor(1,255,0,0)
Render() : OffIMG = GetImage(0,0,32,32)
DeleteVirtualButton(1)
EndFunction
Function CenterWindow()
X = GetMaxDeviceWidth()/2.0 - GetWindowWidth()/2.0
Y = GetMaxDeviceHeight()/2.0 - GetWindowHeight()/2.0
SetWindowPosition( X,Y)
EndFunction
i just re-read the
title here and your use of Exit is exiting the for/next loop . ie, if a specific vbutton is pressed, the remaining vbuttons are not checked in that Do/Loop (which there is nothing set to prompt it to leave).
if you want to exit THAT loop, the exit needs to be outside of the For/Next or some other way.
otherwise, i see no other screen for you to move on to but i think i better understand now that i've re-read so maybe within the For/Next, if a button is Pressed, set a Flag. then outside of the For/Next do something like:
which will kick you outside of the Do/Loop
now,
again, looking at your code. if you're not toggling like i first thought, once you set a button's up and down images, there is no need for you to set anything where the vbutton will automatically use whichever image is assigned to each state.
yup. i'm confused on what ur trying to do. sorry about that