31 lines
1009 B
Plaintext
31 lines
1009 B
Plaintext
on keyDown k
|
|
local ops, nums, allowedKeys, numsCopy, expr
|
|
put "+,-,/,*,(,)" into ops
|
|
put the text of fld "YourNumbersField" into nums
|
|
put the text of fld "EvalField" into expr
|
|
if matchText(expr & k,"\d\d") then
|
|
answer "You can't enter 2 digits together"
|
|
exit keyDown
|
|
end if
|
|
repeat with n = 1 to the number of chars of expr
|
|
if offset(char n of expr, nums) > 0 then
|
|
delete char offset(char n of expr, nums) of nums
|
|
end if
|
|
end repeat
|
|
put ops & comma & nums into allowedKeys
|
|
if k is among the items of allowedKeys then
|
|
put k after expr
|
|
delete char offset(k, nums) of nums
|
|
replace comma with empty in nums
|
|
try
|
|
put the value of merge("[[expr]]") into fld "AnswerField"
|
|
if the value of fld "AnswerField" is 24 and nums is empty then
|
|
answer "You win!"
|
|
end if
|
|
end try
|
|
pass keyDown
|
|
else
|
|
exit keyDown
|
|
end if
|
|
end keyDown
|