Timing an Event
Posted: Fri Nov 05, 2010 3:57 am
This is the first little script that I have written all by myself.
I know there are lots of ways to make a timer, but all of those seems to be for situations where you want to actually see the timer happening. I just want to figure out how long it takes a student to play the game. That I couldn't find (searching for "time" was too broad, searching for "timer" and "counter"took me to the kinds of timers I describe above). Looking in the Lessons place didn't help me either. So, I looked up everything I could think of in the dictionary that might help me.
It seems silly, and it took me many hours to figure it out, but I am very proud of myself.
I present it here, however, not for a pat on the back, but to ask you to please just take a look-see at it.
The conversion of the raw seconds into a time format is very chunky. It works, but I am sure it blocky and inelegant, the brute force method of an inexperienced beginner. "format," "time," "hour," "minute" searches of the dictionary, however, could provide me with nothing better. I tried to convert the seconds to time, but it kept returning a time that was 4 hours larger than it should have been (14 minutes and 24 seconds would be converted to 4:14:24 PM), and I don't need the PM.
I didn't want to do a counting timer partly because, while it would be a good programming exercise for me, it was hurting my head just thinking about it, and I was worried that other things would have to stop while it was doing its thing, but mostly because the computers it will run on are all of different ages, some of which are very slow, and I have already noticed that my laptop waits for shorter seconds than does the desktop computers in my room that the children use, and the computers in the computer lab and the Special Ed room are different as well. I worried that counting on different computers would give different results.
I thought that just getting the twice, finding the difference, and converting it to a min:sec format would be better for me (I tried just subtracting one time from the other, but, as you can imagine, that didn't work, hehe)
There are several bits of the code that are there just for illustrative purposes and so that I could see what was happening. In my game, the buttons and fields will be unnecessary, as the result will be part of a larger field.
So, is there a better way I could have done this? For example, would using convert and then deleting the first and last parts (the 4: and the PM) be better? Oh! Should I turn this into a function? *trembles in fear*
I learned a lot from doing this one myself; building on it or going in another direction will teach me even more.
thank you kindly,
Bantymom
I know there are lots of ways to make a timer, but all of those seems to be for situations where you want to actually see the timer happening. I just want to figure out how long it takes a student to play the game. That I couldn't find (searching for "time" was too broad, searching for "timer" and "counter"took me to the kinds of timers I describe above). Looking in the Lessons place didn't help me either. So, I looked up everything I could think of in the dictionary that might help me.
It seems silly, and it took me many hours to figure it out, but I am very proud of myself.
I present it here, however, not for a pat on the back, but to ask you to please just take a look-see at it.
The conversion of the raw seconds into a time format is very chunky. It works, but I am sure it blocky and inelegant, the brute force method of an inexperienced beginner. "format," "time," "hour," "minute" searches of the dictionary, however, could provide me with nothing better. I tried to convert the seconds to time, but it kept returning a time that was 4 hours larger than it should have been (14 minutes and 24 seconds would be converted to 4:14:24 PM), and I don't need the PM.
I didn't want to do a counting timer partly because, while it would be a good programming exercise for me, it was hurting my head just thinking about it, and I was worried that other things would have to stop while it was doing its thing, but mostly because the computers it will run on are all of different ages, some of which are very slow, and I have already noticed that my laptop waits for shorter seconds than does the desktop computers in my room that the children use, and the computers in the computer lab and the Special Ed room are different as well. I worried that counting on different computers would give different results.
I thought that just getting the twice, finding the difference, and converting it to a min:sec format would be better for me (I tried just subtracting one time from the other, but, as you can imagine, that didn't work, hehe)
There are several bits of the code that are there just for illustrative purposes and so that I could see what was happening. In my game, the buttons and fields will be unnecessary, as the result will be part of a larger field.
So, is there a better way I could have done this? For example, would using convert and then deleting the first and last parts (the 4: and the PM) be better? Oh! Should I turn this into a function? *trembles in fear*
I learned a lot from doing this one myself; building on it or going in another direction will teach me even more.
Code: Select all
--Button "Start Timer"
on mouseUp
put the seconds into Field "Start Timer"
end mouseUp
--Button "Stop"
on mouseUp
put the seconds into Field "End"
put field "End" - field "Start" into tRawSeconds
if tRawSeconds > 60 then
put the trunc of (tRawSeconds / 60) into tMinutes --lol, so proud of myself for putting this all in one line!
put tRawSeconds - (tMinutes * 60) into tSeconds
if tSeconds < 10 then
put tMinutes & ":0" & tSeconds into field "Time"
else
put tMinutes & ":" & tSeconds into field "Time"
end if
else
if tSeconds < 10 then
put ":0" & tRawSeconds into field "Time"
else
put ":" & tRawSeconds into field "Time"
end if
end if
put tRawSeconds into field "Time2"
convert field "Time2" to long time --all this is just to show what happens with convert
end mouseUp
Bantymom