reset points after end game

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello I have a problem with my game, I can not reset the points and the time counter when I start a new game time counter and points are displayed on the label
if I try to write lblpoints = "" or declare a variable as int dim points and then I write to point = 0 can not get to zero, when I press the button for a new game, the time counter and points continue from 'last game ended.
 

fifiddu70

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim ri As Int
   ri= Rnd (1,33)
   Dim points  As Int 
   points = 0
        Dim counter1 As Int
        counter1 = 0
        
End Sub

Sub Globals
   
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim mp3 As MediaPlayer
   Dim img1 As ImageView
   Dim img2 As ImageView
   Dim lblpoints As Label
   Dim lblpunti As Label
   Dim timer1 As Timer
   Dim timer2 As Timer
   Dim timer3 As Timer
   Dim timer4 As Timer
   Dim timer5 As Timer
   Dim timer6 As Timer
   Dim timer7 As Timer
   Dim timer10 As Timer
   Dim img3 As ImageView
   Dim img4 As ImageView
   Dim btnstart As Button
   Dim live As Int
   live = 2
   Dim lblcounter As Label
   Dim img As ImageView
   Dim lbllive As Label
   Dim lbllive3 As Label
   Dim pippo As Int
   Dim lblsound As Label
   Dim answ As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("tapsmiley")
   
   mp.Initialize 
   mp2.Initialize
   mp3.Initialize
   img1.Visible = False
   img2.Visible = False
   img3.Visible = False
   img4.Visible = False
   
   End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnstart_Click
   
   mp2.Load(File.DirAssets,"okmusic.mp3")
   mp2.Play
   mp2.Looping = True
   points = 0
        counter1=0
   lblcounter.Text  = counter1
   lblpoints.Text  = points
   lbllive3.Text = 3
   ri= Rnd (1,33)
   img1.Bitmap=LoadBitmap(File.DirAssets,ri &".gif")
   img1.Visible = True
   
End Sub

Sub Activity_KeyPress (KeyCode As Int)  As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then   
   mp2.Stop
   
   answ = Msgbox2("SEI SICURO DI VOLER USCIRE?","AVVISO","SI","","NO",Null)
   If answ = DialogResponse.NEGATIVE Then
   mp2.Load(File.DirAssets,"okmusic.mp3")
   mp2.Play
   mp2.Looping = True
   Return True
   
   End If
   End If
   Activity.Finish
   Return False
End Sub
code:
 
Upvote 0

HotShoe

Well-Known Member
Licensed User
Longtime User
Try:

B4X:
Sub Activity_KeyPress (KeyCode As Int)  As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then    
    mp2.Stop
    
    answ = Msgbox2("SEI SICURO DI VOLER  USCIRE?","AVVISO","SI","","NO",Null)
    If answ = DialogResponse.NEGATIVE Then
    btnstart_Click
    Return True
    
    End If
    End If
    Activity.Finish
    Return False
End Sub
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
no, i have problem when press button start, the points score not restart to zero, if try press start button withouth exit, the hig score points and counter not restart to zero.
 
Upvote 0

anallie0

Active Member
Licensed User
Longtime User
The sub is correct. values ​​are set to 0. Probably somewhere there will be some code that reloads the value of instruction.

la sub è corretta . i valori vengono impostati a 0. Probabilmente da qualche altra parte del codice ci sarà qualche istruzione che ricarica il valore.
 
Upvote 0

anallie0

Active Member
Licensed User
Longtime User
try putting a log in the sub btnstart_Click. after zero values

prova a mettere un log nella sub btnstart_Click. dopo l'azzeramento dei valori
 
Upvote 0
Top