The WIL Tutorial
|
Here is the final working version of the WIL program that we've slowly been building throughout this tutorial.
It incorporates many of the concepts that we've discussed so far, as well as using some arithmetic (*, -, +) and relational (<) operators that are covered in the section on Operators.
It can also be improved and customized in a number of ways, but we'll leave that up to you.
If you can understand and follow the structures and processes illustrated in this sample file, and can begin to incorporate them into your own WIL programs, you are well on your way to becoming a true WIL guru!
|
|
Tutor.wbt |
; tutor.wbt
mins = AskLine("Solitaire", "How many mins do you want to play?", "", 0)
mins = Int(mins)
Switch mins
case 0
Display(5, "", "Game canceled")
exit
break
case 1
Message("Only a minute?", "Wow! You've got willpower.")
break
case 2
Message("2 Minutes?", "This isn't much of a break.")
break
case 3
Message("3 Minutes?", "You're barely got time to shuffle")
break
case 4
Message("HA,HA,HA", "I dare you to try to beat me.")
break
case mins ;default case - must be last in the switch
Message("THAT LONG!!!", "Where did you get all that time?")
break
EndSwitch
;;ADDED to demonstrate checking for the existence of a program
;;before running a second occurrence.
If WinExist("Solitaire") == @TRUE
WinActivate("Solitaire")
WinShow("Solitaire")
Else
Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")
Endif
for i = 0 to 9
j=100-i*10
k=300+i*70
WinPlace(j,j,k,k,"Solitaire")
next
WinZoom("Solitaire")
; ADDED to show an example of sending keystrokes.
SendKeysTo("Solitaire", "!gc{RIGHT}{SP}~")
GoSub dumdedum
mins=AskLine("More Time?", "Enter additional minutes", 0, 0)
If mins!=0 then GoSub dumdedum
;;ADDED as an example of a while loop.
while WinExist("Solitaire")
WinClose("Solitaire") ;Make sure it closes
endwhile
Message("Time's Up", "Get Back to Work!")
Exit
:dumdedum
goal = mins * 60
timer = 0
While timer < goal
remain = goal - timer
if WinExist("Solitaire")
WinTitle("Solitaire", "Solitaire (%remain% seconds left)")
else
exit
endif
TimeDelay(10)
timer = timer + 10
EndWhile
Return