I have questions to the following subroutine demo
I use the debug mode and Version 9.8 of B4A
Both variants with do until hint=.... loop and do while hint<>.... loop does not work as I expected.
In my understanding in conditional loops like do while or do until, the condition is checked for every loop
The function hint returns a byte value. Capital letters are public constants of a class module.
The code of the subs demo, hint is listed and the declaration of the constants too.
When I use the build in debug functions of B4A to check the program flow of the sub demo I encounter the following
A} The function cheat is called
B} The function hint is called and returns an value 5 means GAME_HAS_SOLUTION
The function hint set for two buttons of an array the color to COLORHINT (equals to blue)
C} Because the while condition is fulfilled the program flow continues with the sleep(5000) instruction
D) After the sleeping time, the color of the two changed buttons are setback to gray
I expect now the program flow back to Do While program line and calling the function hint again to check the condition.
D} But the program flow continues with the Sleep(5000) instruction instead checking the While condition again.
E} Commenting the sleep instruction gives the same result. The while condition is not checked again, means the function hint is not called
F} Same program flow I experienced with Do Until ... Loop which is commented in the source code now
What is the problem?
What I am doing wrong?
Any hint is welcome! The program will not work as I expected in this way
What I have to change to correct the program flow?
I will not believe that this is a bug of B4A, because I guess others, more busy with B4A, will recognize this earlier than me. Right?
I still post in BUG? because I expect a more helpful answers from here.
EDIT
Playing around with the problem, I found
The sub hint is called for every loop to check the condition as I expected, but the program flow calling the sub hint is not shown in the debug session, means when the while condition is checked a further time the debugger does not step through the sub hint. I add a log instruction in the sub hint and discover the sub hint is called. I set a break point at the log instruction in the sub hint. When the sub hint is called a further time to check the While condition the debugger does not step through the lines of the sub hint. The sub hint is running without support of the debugger.
More general
When the condition of the While loop is checked the first time, the debugger steps through the sub hint. If the while condition is checked a further time during looping the debugger does not step through a sub part of the while condition. Breakpoints in the sub needs to be evaluated for the while condition are also not recognized.
So the program flow for my application is right, I can continue debugging the application keeping in mind that the debugger seems to have a small problem
May be a bug?
I use the debug mode and Version 9.8 of B4A
Both variants with do until hint=.... loop and do while hint<>.... loop does not work as I expected.
In my understanding in conditional loops like do while or do until, the condition is checked for every loop
The function hint returns a byte value. Capital letters are public constants of a class module.
The code of the subs demo, hint is listed and the declaration of the constants too.
When I use the build in debug functions of B4A to check the program flow of the sub demo I encounter the following
A} The function cheat is called
B} The function hint is called and returns an value 5 means GAME_HAS_SOLUTION
The function hint set for two buttons of an array the color to COLORHINT (equals to blue)
C} Because the while condition is fulfilled the program flow continues with the sleep(5000) instruction
D) After the sleeping time, the color of the two changed buttons are setback to gray
I expect now the program flow back to Do While program line and calling the function hint again to check the condition.
D} But the program flow continues with the Sleep(5000) instruction instead checking the While condition again.
E} Commenting the sleep instruction gives the same result. The while condition is not checked again, means the function hint is not called
F} Same program flow I experienced with Do Until ... Loop which is commented in the source code now
What is the problem?
What I am doing wrong?
B4X:
Sub demo
cheat
' Do Until hint=Starter.llk.GAME_NEEDS_SHUFFLE
' Sleep(5000)
' Buttons(Starter.llk.lastfound(0).row+1,Starter.llk.lastfound(0).col+1).Color=Colors.gray
' Buttons(Starter.llk.lastfound(1).row+1,Starter.llk.lastfound(1).col+1).Color=Colors.gray
' Loop
Do While hint<>Starter.llk.GAME_NEEDS_SHUFFLE
Sleep(5000)
Buttons(Starter.llk.lastfound(0).row+1,Starter.llk.lastfound(0).col+1).Color=Colors.gray
Buttons(Starter.llk.lastfound(1).row+1,Starter.llk.lastfound(1).col+1).Color=Colors.gray
Loop
game_over(True)
End Sub
B4X:
Sub hint As Byte
If Starter.llk.status<>Starter.llk.GAME_RUN Or Starter.llk.hint=0 Then Return Starter.llk.GAME_PROBLEM
Starter.llk.hint=Starter.llk.hint-1
If Starter.llk.no_solution=Starter.llk.GAME_HAS_SOLUTION Then
'solution in lastfound!
Buttons(Starter.llk.lastfound(0).row+1,Starter.llk.lastfound(0).col+1).Color=Starter.llk.COLORHINT
Buttons(Starter.llk.lastfound(1).row+1,Starter.llk.lastfound(1).col+1).Color=Starter.llk.COLORHINT
End If
Return Starter.llk.status
End Sub
B4X:
Sub Class_Globals
Public CONST DIFFICULTY_EASY As Byte = 0
Public CONST DIFFICULTY_NORMAL As Byte = 1
Public CONST DIFFICULTY_HARD As Byte = 2
Public CONST DIFFICULTY_EXPERT As Byte = 3
Public CONST DIFFICULTY_RESUME As Byte = 4
Public CONST DIFtoString() As String = Array As String("DiffiCULTY_EASY", "DiffiCULTY_NORMAL", "DiffiCULTY_HARD", "DiffiCULTY_EXPERT", "DiffiCULTY_RESUME")
Public CONST MAX_PLAYTIME() As Long = Array As Long(200000,250000,300000,500000)
Public CONST GAME_STOPPED As Byte = 0
Public CONST GAME_NEEDS_SHUFFLE As Byte = 1
Public CONST GAME_LEVEL_FINISHED As Byte = 2
Public CONST GAME_PROBLEM As Byte = 3
Public CONST GAME_FINISHED As Byte = 4
Public CONST GAME_HAS_SOLUTION As Byte = 5
Public CONST GAME_NO_SOLUTION As Byte = 6
Public CONST GAME_RUN As Byte = 7
Public CONST GAMEtoString() As String = Array As String("GAME_STOPPED", "GAME_NEEDS_SHUFFLE", "GAME_LEVEL_FINISHED", "GAME_PROBLEM", "GAME_FINISHED", "GAME_HAS_SOLUTION", "GAME_NO_SOLUTION", "GAME_RUN", "GAME_MAXLEVEL")
Public CONST GAME_MAXLEVEL As Byte = 8
Public CONST PLAYSOUND As Boolean = True
Public CONST HIDE As Byte = 0
Public CONST MAX_SHUFFLE As Byte = 3
Public CONST COLORHINT As Int = Colors.Blue
Public CONST NO_CHANGE As Byte = 0
Public CONST MOVE_DOWN As Byte = 1
Public CONST MOVE_LEFT As Byte = 2
Public CONST MOVE_UP_DOWN_SEPARATE As Byte = 3
Public CONST MOVE_LEFT_RIGHT_SEPARATE As Byte = 4
Public CONST MOVE_UP_DOWN_CONVERGE As Byte = 5
Public CONST MOVE_LEFT_RIGHT_CONVERGE As Byte = 6
Public CONST MOVE_UP_LEFT_DOWN_RIGHT As Byte = 7
Public CONST MOVE_LEFT_DOWN_RIGHT_UP As Byte = 8
Public CONST MOVE_DISPERSE As Byte = 9
Public CONST MOVE_CENTRAL As Byte = 10
Public CONST CHANGEtoString() As String = Array As String ("NO_CHANGE", "MOVE_DOWN", "MOVE_LEFT", "MOVE_UP_DOWN_SEPARATE", "MOVE_LEFT_RIGHT_SEPARATE", "MOVE_UP_DOWN_CONVERGE", "MOVE_LEFT_RIGHT_CONVERGE", "MOVE_UP_LEFT_DOWN_RIGHT", "MOVE_LEFT_DOWN_RIGHT_UP", "MOVE_DISPERSE", "MOVE_CENTRAL")
Any hint is welcome! The program will not work as I expected in this way
What I have to change to correct the program flow?
I will not believe that this is a bug of B4A, because I guess others, more busy with B4A, will recognize this earlier than me. Right?
I still post in BUG? because I expect a more helpful answers from here.
EDIT
Playing around with the problem, I found
The sub hint is called for every loop to check the condition as I expected, but the program flow calling the sub hint is not shown in the debug session, means when the while condition is checked a further time the debugger does not step through the sub hint. I add a log instruction in the sub hint and discover the sub hint is called. I set a break point at the log instruction in the sub hint. When the sub hint is called a further time to check the While condition the debugger does not step through the lines of the sub hint. The sub hint is running without support of the debugger.
More general
When the condition of the While loop is checked the first time, the debugger steps through the sub hint. If the while condition is checked a further time during looping the debugger does not step through a sub part of the while condition. Breakpoints in the sub needs to be evaluated for the while condition are also not recognized.
So the program flow for my application is right, I can continue debugging the application keeping in mind that the debugger seems to have a small problem
May be a bug?
Last edited: