Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #4 on: May 12, 2012, 06:37:31 am » |
@Grumpy_Mike
O.k I will have a look and see if I can do that im not to sure!
Here is the Director script
-- Main Movie Script:
on startMovie initialiseGlobals() end
global gTheKeys, gKeysTriggered global gActivePads, gReEnter
on initialiseGlobals -- Reset everything: gTheKeys = ["e", "r", "p"] gKeysTriggered = [0, 0, 0] gActivePads = [0, 0, 0] -- [0,0,0]=NONE, [1,0,0]=LEFT, [0,1,0]=RIGHT, [1,1,1]=BOTH gReEnter = 0 end
on detectKeyInputs repeat with i = 1 to 3 if keyPressed(gTheKeys.getAt(i)) then gKeysTriggered.setAt(i, 1) else gKeysTriggered.setAt(i, 0) end if end repeat end
on resetMovie go to "initMovie" end
-- Timer script, used to filter out unwanted keypresses, sorta like a threshold: global gTrackLeft, gTrackRight global gTimeInterval, gHistoryLength, gHistoryCounter
on initTimer gTimeInterval = .25 * 60 gHistoryCounter = 1 gHistoryLength = 10 --init the list to store the keypresses gTrackLeft = [] gTrackRight = [] repeat with i = 1 to gHistoryLength gTrackLeft.append(0) gTrackRight.append(0) end repeat startTimer end
on recordKeyHistory if the Timer > gTimeInterval then -- set list positions: gTrackLeft.setAt(gHistoryCounter, (gKeysTriggered.getAt(1))) -- update from left key gTrackRight.setAt(gHistoryCounter, (gKeysTriggered.getAt(2))) -- update from right key -- move to next position if gHistoryCounter >= gHistoryLength then gHistoryCounter = 1 else gHistoryCounter = gHistoryCounter + 1 end if -- put gHistoryLength -- put gHistoryCounter --put gTrackLeft -- put gTrackRight startTimer end if end
on getFilteredKeyInput valL = 0 valR = 0 repeat with i = 1 to gHistoryLength -- count number of 1's (ON) in the list. if gTrackLeft.getAt(i) = 1 then -- LEFT key valL = valL + 1 end if if gTrackRight.getAt(i) = 1 then -- RIGHT key valR = valR + 1 end if end repeat if valL > (gHistoryLength/2) then -- is more than half the list = 1 / ON? gActivePads.setAt(1, 1) -- yep it is else gActivePads.setAt(1, 0) -- nope it aint end if if valR > (gHistoryLength/2) then -- ditto for the RIGHT key gActivePads.setAt(2, 1) else gActivePads.setAt(2, 0) end if -- If both LEFT and RIGHT active then light up position 3 in the list! if gActivePads.getAt(1) = 1 and gActivePads.getAt(2) = 1 then gActivePads.setAt(3, 1) else -- or not! gActivePads.setAt(3, 0) end if end
on updateKeys getFilteredKeyInput() end
|