Show a button when label.text = 100

Zate

Member
Hey,
I want my app to show a button when label.text is 100.
That's how my game works:
you have to kill mosquitos by tapping them, I made mosquitos appear randomly and every time they disappear (no matter if you killed them or not) the label value increase of 1. I don't want the game to be infinite, I want that when label.text = 100 a button appear and by clicking it you can see the result.
The code should be:
If lblscore = 100 then
(all labels/mosquitos disappear)
(all timers stop)
btnresult.visible = true
btnresult.enabled = true
End if

I didn't write all the labels and timers name because it would make this complicate.

My question is: in which routine should I write the code in? I have no idea...
Maybe I should have used edittext... but I prefer to keep label if possible now that I've written a good part of the code
 
Last edited:

kickaha

Well-Known Member
Licensed User
Longtime User
Zate,

I have shortened your code so that it is easier to insert a game end, pm me and I will send it to you.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Ah, maybe because you are notregistered user.

So, short version:

Label1_Click to Label9_Click can be replaced with
B4X:
Sub Label1_Click
       LabClick (Timer1b, Timer1, Label1)
End Sub
.
.
.
Sub Label9_Click
       LabClick (Timer9b, Timer9, Label9)
End Sub

With this sub included in your code
B4X:
Sub LabClick (TimB As Timer, Tim As Timer, Lab As Label)
    TimB.Enabled = True
   Lab.SetBackgroundImage(LoadBitmap(File.DirAssets, "Macchia_Sangue.gif"))
   Lab.Enabled = False
   Label11.Text = Label11.Text + 1
   Label13.Text = Label13.Text + 1
   Tim.Enabled = False
End Sub

Similarly, Timer1_Tick to Timer9_Tick can be replaced with

B4X:
Sub Timer1_Tick
   TimerGone (label1, timer1)
End Sub
.
.
.
.
Sub Timer9_Tick
   TimerGone (label9, timer9)
End Sub

With this sub in your code
B4X:
Sub TimerGone (Lab As Label, Tim As Timer)
   Lab.Visible=False
   Lab.Enabled=False
   Tim.Enabled = False
   Label13.Text = Label13.Text + 1
End Sub

Now, instead of adding 1 to Label13 (I presume this is your counter), you can write a sub to add 1 to it, check its value, and if it is 100 then do your stuff.
 
Upvote 0

Zate

Member
The sub may be:
B4X:
Sub EndGame
    If Label13.Text = 100 Then
        [I]things[/I]
    Else
        Label13.text = Label13.Text +1
    End If
End Sub
What do I have to write next to EndGame? Nothing happens. The game keep going.
 
Last edited:
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
The sub may be:
B4X:
Sub EndGame
    If Label13.Text = 100 Then
        [I]things[/I]
    Else
        Label13.text = Label13.Text +1
    End If
End Sub
What do I have to write next to EndGame? Nothing happens. The game keep going.

This is a conversion problem, try
B4X:
    If Label13.Text = "100.0" Then
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Try this modified version, I have commented the lines I have changed.

I am working on a game with the same sort of mechanics at the moment, and you can do this all with one timer!
 

Attachments

  • zanzar2.zip
    29.5 KB · Views: 213
Upvote 0

Zate

Member
It works! Thanks a lot for your patience! But tell me...
B4X:
Log ("endgame called")
What does it mean?
 
Last edited:
Upvote 0
Top