Timer works with msgbox pause, but not without

I have a timer that controls an animation of dice and then yields the random dice number. This works fine when it is triggered from a mouse-down event and then waits for another mouse click. However, I want to have the timer activated from code when the computer is playing with me.

Here’s the problem. When the computer routine calls the timer, the animation works fine, but the dice number is returned before the animation is activated. When I put a msgbox into the code before it returns the dice value to the computer routine I get the correct number, but if I omit the msgbox then it returns O. Also the presence or absence of the msgbox affects where the timer mode is O (with msgbox) or 2 (without msgbox).

This is the function that activates the timer. It is called either from a mouse-down event in the same window or a method from a module. (The module contains the computer methods that imitate the mouse-down events)

[code]
nextRound=true
gDiceRoll=true
count=0
dicedual.play
DiceTimer.Mode=2
bNext.Caption=“NEXT”
if gDiceRoll=false then

'msgbox "Dice: "+str(groll)+" Mode: "+str(DiceTimer.mode)
return gRoll

end[/code]

Here is the timer code:

[code] dim r as new random
dim n,i,w,h as integer
w=(cDice.Widthgr).1
h=(cDice.Heightgr).15
n=r.InRange(1,6)
gTheDie=gDice(n)
groll=n
i=r.InRange(1,10)
n=(5-i)*2
twoDice=false

w=w*2.5

diceX(1)=w+n
diceY(1)=h+n
cDice.Refresh
count=count+1
if count>10 then
me.mode=0
gDiceRoll=false
'MsgBox str(groll)
end[/code]

Mac OS10.10.5 Xojo 2013 release 3.3 (I know, but I don’t program often enough to want to deal with all the redactions and deprecations for this old game of mine)

Solved
Realized that I would have to call the computer play from the timer and not the other way around. The msgbox just caused an artificial stop that allowed the timer to run, but it didn’t without that stop. The computer players roll the dice as planned and expected.