Hi, I am at a loss as to how the program the following:
I have 2 buttons, let's call them "A" and "B". People using my program will be clicking on these two buttons often and in any order that they like. For example, somone might click on them in this order: A A A B B B B A A A A B B B B B B B B A A A
I would like to know the following things:
1. the number of times they switch a series of clicks from one button to the next. For example, in the series above they switched 4 times.
2. the average number of clicks made in each series of button clicks. For example, in the series above this would be (3+4+4+8+3) / 5 = 4.4
Thanks for any help,
Ac
Calculating number of button clicks and switches
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Here's a quick and dirty solution using three fields and three buttons.
1. Field "Switches" without script
2. Field "Average" without script
3. Field "Sequence" with script:
4. Button "A" with script:
5. Button "B" with script:
6. Button "Clear" with script:
Hope this helped,
Jan Schenkel.
1. Field "Switches" without script
2. Field "Average" without script
3. Field "Sequence" with script:
Code: Select all
on RecalcStatistics
-- init some variables
put the text of me into tText
put char 1 of tText into tPrevChar
put 0 into tSwitchCount
put 1 into tSequenceLength
put empty into tSequenceLengthList
-- now iterate over the text
repeat with i = 2 to length(tText)
if char i of tText is not tPrevChar then
-- we have a switch
add 1 to tSwitchCount
put tSequenceLength & comma after tSequenceLengthList
put 1 into tSequenceLength
put char i of tText into tPrevChar
else
add 1 to tSequenceLength
end if
end repeat
-- don't forget to take the last sequence into account
add 1 to tSwitchCount
put tSequenceLength after tSequenceLengthList
-- update the average and swtich count fields
put average(tSequenceLengthList) into field "Average"
put tSwitchCount into field "Switches"
end RecalcStatistics
Code: Select all
on mouseUp
put "A" after field "Sequence"
send "RecalcStatistics" to field "Sequence"
end mouseUp
Code: Select all
on mouseUp
put "B" after field "Sequence"
send "RecalcStatistics" to field "Sequence"
end mouseUp
Code: Select all
on mouseUp
put empty into field "Sequence"
send "RecalcStatistics" to field "Sequence"
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com