12-02-2024, 06:17 PM
Similar to just setting a flag but doing so with an event...
Okay, let's pretend that message routine was a full blown word processor of around 8000 lines of code. That would take some hefty planning to make it a flow through routine back to the animation in the main; so a solution is to do as in the code above, make it call the animate routine in both the main and the wp message routine. Of course if it was really just a small program, as above, I would have coded then message routine to flow through to the main. The reason is because a program is easier to understand and debug when the programmer can easily figure out which routine was the calling routine. One call to animate is better than two, in this case.
Pete
Code: (Select All)
' Main
Cls
Locate 10, 2: Print "Message";: Color 7 + 16: Print ":";: Color 7, 0
Do
keyboard key$
If Len(key$) Then
If LCase$(key$) >= "a" And LCase$(key$) <= "z" Or key$ = " " Then
message key$
If key$ = Chr$(13) Then
Locate 10, 11: Print Space$(_Width - Pos(0)); ' Message sent.
Locate 10, 2: Print "Message";: Color 7 + 16: Print ":";: Color 7, 0 ' Ready for next message.
End If
If key$ = Chr$(27) Then Exit Do
End If
End If
animate
Loop
End
Sub keyboard (key$) ' Flow-through sub-routine.
_Limit 30
key$ = InKey$
End Sub
Sub message (key$) ' Non-flow-through sub-routine.
y = 10: x = 10
Locate 10, 2: Print "Message:"; ' Stops colon from flashing.
Do
animate: Locate y, x + 1, 1 ' animation routine is called again here.
If LCase$(key$) >= "a" And LCase$(key$) <= "z" Or key$ = " " Then
If x < _Width Then x = x + 1: Locate y, x, 1: Print key$;: x = Pos(0) - 1
End If
If key$ = Chr$(8) And x > 10 Then Locate y, x: Print " ";: x = Pos(0) - 2
keyboard key$
Loop Until key$ = Chr$(13) Or key$ = Chr$(27)
End Sub
Sub animate ' Flow-through sub-routine.
Static ii, z
If Abs(Timer - z) > .25 Then
z = Timer
If ii Then Locate 15, ii, 0: Print " "; Else Locate 15, _Width: Print " ";
ii = ii + 1
Locate 15, ii, 0: Print Chr$(254);
If ii = _Width Then ii = 0
End If
End Sub
Okay, let's pretend that message routine was a full blown word processor of around 8000 lines of code. That would take some hefty planning to make it a flow through routine back to the animation in the main; so a solution is to do as in the code above, make it call the animate routine in both the main and the wp message routine. Of course if it was really just a small program, as above, I would have coded then message routine to flow through to the main. The reason is because a program is easier to understand and debug when the programmer can easily figure out which routine was the calling routine. One call to animate is better than two, in this case.
Pete