Pairs4Android Bug

Cableguy

Expert
Licensed User
Longtime User
Hi...I have persistent bug that keeps on...bugging me!!!

In whatever level, since some of the subs are similar, if not equal, I coded the buttons to be invisible after button click, so they wouldn't be able to fire the sub again, forcing the player to choose another Button...
It happens that the button does NOT get invisible, and taping in the imageview, fires the button click event...
I have tried several aproaches to solve this, but no luck...
All buttons fire the same event...
Heres the sub..:
B4X:
Sub Btn_Click
   Sound.Play
   Dim value, imgn As String
   If Timer2.Enabled = True Then Return
   If Counter = 0 Then
      Butao1 = Sender
      Anim0.Start(Butao1)
      Butao1.Visible = False
      Counter = 1
   Else If Counter = 1 Then
      Butao2 = Sender
      Anim1.Start(Butao2)
      Butao2.Visible = False
      Dim Buttons() As Button
         Buttons = Array As Button(Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8,Button9,Button10,Button11,Button12,Button13,Button14,Button15,Button16)
         For i = 0 To Buttons.Length - 1
            Buttons(i).Enabled = False  
              Next
      If Butao1.Tag = Butao2.Tag Then
         Value = Label2.Text + Score
         Label2.Text = Value
         Pair = Pair + 1
         Dim Buttons() As Button
            Buttons = Array As Button(Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8,Button9,Button10,Button11,Button12,Button13,Button14,Button15,Button16)
            For i = 0 To Buttons.Length - 1
               Buttons(i).Enabled = True  
          Next
         Butao1.Enabled = False
         Butao2.Enabled = False
      Else
         Timer2.Enabled = True
      End If
   Counter = 0
   Ticks = Ticks + 1
   End If
   If Pair = MaxPair Then
      Timer1.Enabled = False
      TotalScore = NumberFormat(((((1/((Label4.Text * 60 )+ Label6.Text))*Label2.Text) + (1/Ticks))*100)+Score * MaxPair,0,0)
      Timer3.Enabled = True
   End If
End Sub
 
Last edited:

splatt

Active Member
Licensed User
Longtime User
B4X:
If Butao1.Tag = Butao2.Tag Then

Where and what do these values get set\altered to?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
B4X:
If Butao1.Tag = Butao2.Tag Then

Where and what do these values get set\altered to?

Those are set using the sender keyword, so that butao1.Tag, wich is th tag od the first button tapped, can be compared with butao2.Tag, wich is the second button tapped, if no match, then hide the images again and continue the game..That part of the sub is not the issue,...I just don't understand WHY the ButaoX.Visible = False is never duely executed, althought the imageview does como to foreground!
Tapping one already successfully compared pair, actually makes tose buttons invisible...that is to say, that even just by tapping on the IMAGEVIEW, the buttons click event is being fired!!!
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Why are you starting an animation before hiding the button?
You can also disable the button by setting its Enable property to false.

I have tried setting the enabled property to flase, but I believe that it is the Imageview that fires the btn_click event when tapped...
I start the animations before setting the button visibile to false, because doing it the other wat around, causes the button to be invisible for a fractions of second and the visible to start the animation...

Now That I have Uploaded it to the market, I will Post the Project signed with the debug key...
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
ImageView views were added in the designer, and no change to the default values were made...
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Still I can't figure out why the buttons do not get fully invisible, and seem to only get send to background!
I have posted the ZIP under the Share YourCreations forum, if you wanna take a quick look at the code..
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
First verify that there are no other views that raise this event.
Then try to comment the animation code. Starting an animation and then immediately hiding the view may cause some unexpected behavior.
You can also check the Visible property of the Sender button.

Will Do, I will come back wih my findings, if any...
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
HI again EREL...


I've tryed EVERITHING I could think of, comenting out the anims, using a temp var to hold the last button tapped, even setting Butao1.removeview, but NOTHING works...
The Log(Sender) shows that is always a button that triggers the event, even when I tap on a visible and in the foreground imageview!!!!!
This "Bug" wouldn't be of much importance if it didn't sometimes create an odd behaviour in the game, that if the same button gets tapped for a second time, the comparation result is positive, with only one "card" selected, Still, it does NOT always behave like that!
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
That seems to solve the main issue that sometimes created some odd behaviour on the game...

It seems that firing one single event for a group of views may not be the best coding under android...
Events for "active" views, such as buttons, Imageviews and such, seem to work a lot better if each view has it's own events, and inside that event call a a common sub...

Thaks for the time spendt in this one EREL...
 
Upvote 0
Top