New Math
Rob Cozens
rcozens at pon.net
Sat Jan 11 02:02:01 EST 2003
>Second: I have some funny math going on. It's the same States Quiz. I'm
>trying to have the stack keep a running track of the number of correct
>answers, the number of attempts, and then divide the former by the latter
>and multiply by 100 for an accuracy percentage. For simple math, such as
>3 successes out of 4 tries, the correct percentage (75) is given.
>However, for other results, it's not:
>
>2/3 = 6667
>5/6 = 3333
>6/7 = 4286
>7/8 = 87.5
>8/9 = 8889
>10/11 = 9091
>
>Here's the script:
>
>[snip]
>Aside from the fact that there are probably vastly more elegant scripting
>solutions, can anyone help tell me what is going on?
Hi Judy,
Here's what I tried (on a card with fields "State", "Tries", "Score",
& "Average"):
on mouseUp
set the numberFormat to ".00"
put (field "Tries")+1 into theTries
put theTries into field "Tries"
if field "State" = 7 then
put (field "Score")+1 into theScore
put theScore into field "Score"
end if
put (theScore/theTries)*100 into field "Average"
end mouseUp
Here's what I got in field "Average":
2/3 = 66.67
5/6 = 83.33
6/7 = 85.71
7/8 = 87.50
8/9 = 88.89
10/11 = 90.91
One thing I noticed: After you put theScore into field "Score" you
send mouseUp to field "Play". Is it possible this changes the value
of theScore?
Now to your aside:
You should be able to do what you want to do with one handler in the
card script or a group script if your state images are grouped. One
way to do this would be to name each image [stateName].gif and give
each image a stateNumber property (eg: set the stateNumber of image
"Utah.gif" to 7). Then you could script something like:
on mouseUp
global theState, theScore, theMClick, theTries, theAverage
get the stateNumber of the target
if it is empty then exit mouseUp -- logic to make sure the target
is a state image.
if theMClick = 0 then
answer "Please click on the 'Play' button!"
exit mouseUp
end if
add 1 to theTries
if it = theState then
answer "Correct. This is the State of"&&(char 1 to -5 of the
short name of the target)&"."
add 1 to theScore
put 0 into theMClick
put empty into fld "Instructions"
send mouseUp to btn "Play"
else answer "No, this is not correct. Please try again."
put theTries into fld "Tries"
put theScore into field "Score"
put (theScore/theTries)*100 into theAverage
put theAverage into fld "Average"
end mouseUp
--
Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.com/who.htm
"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."
from "The Triple Foole" by John Donne (1572-1631)
More information about the use-livecode
mailing list