-- these 2 events show how to use duration lingo -- the first one --================== -- ball falls down, warn when only 4 seconds remaining -- shows elapsed time since start and times out at target time on startMovie -- use eventflag variable to tell when event going global eventflag eventflag = 0 put 0 into word 2 of member "elapsed" put 0 into word 2 of member "countdown" member("startbutton").text = "Start Event" end on idle global targettick, starttick, eventflag,el,cdown curtick = the ticks -- current ticks -- get elapsed time by subtracking start from current -- divide by 60.0 to get seconds el = (curtick-starttick)/60.0 -- get remaining time by subtracking current from target -- divide by 60.0 to get seconds cdown = (targettick-curtick)/60.0 -- show fields only when eventflag = 1 -- set by startevent button -- move ball also if eventflag = 1 then showcountdown moveball end if -- check for time out over target time -- you could go to special event here if cdown <0 and eventflag = 1 then eventflag = 0 beep member("startbutton").text = "Start Event" -- sets eventflag and changes button end if -- check for specific times - take action -- in this situation make warning appear or else dissapea --when between 4 and 3 second -- could call any kind of event - eg sound, picture appear,etc if cdown < 4 and cdown >3 then sprite(5).visible = true else sprite(5).visible = false end if end idle on showcountdown -- put into fields to see - put in second word to leave tag there (eg elapsed= xxx) global el,cdown put el into word 2 of member "elapsed" put cdown into word 2 of member "countdown" end showcountdown on moveball global howlong, el -- figure out distance to move ball for each fraction of second -- divide 400 pixels (length to move) by howlong variable = increment -- then set the vertical position of ball to that increment times elapsed seconds increment = 400.0/howlong position = increment * el sprite(9).locv = position end on startevent -- starting time = current ticks divided by 60.0 -- need the .0 in order to tell director to do fractional decimals not just whole numbers -- target time = starting time + number of seconds till end (variable howlong) -- convert to ticks by multiplying by # seconds (6 in this example) -- change it to be whatever you want global targettick, starttick, eventflag, howlong howlong = 6 starttick = the ticks targettick = starttick + (60*howlong) end on managebutton global eventflag if eventflag = 0 then startevent eventflag = 1 member("startbutton").text = "Stop Event" else eventflag = 0 member("startbutton").text = "Start Event" end if end --======================= --these pertain to the reaction game on frame 25 -- start and try to click the ball as quick as possible on quickeventstart -- this handler sets up the event --- called when click on "start quick envent" button -- makes circle invisible, calculates random postion -- makes it visible -- sets global variable startquicktick with starting time in ticks -- turns off the tracknoactionflag for counting time since last action global startquicktick,eventflag,tracknoactflag eventflag = 2 sprite(3).visible = false x = random(300) y = random(300) sprite(3).loc = point(x,y) put "go" into member "howquick" beep sprite(3).visible = true startquicktick = the ticks tracknoactflag = 0 put "go for it" into member "noclick" end on finishquick -- this handler called when user clicks on circle -- calculates the current time in ticks endclick --subtracts startquicktick from current time = elapsed -- puts it into field called howquick global startquicktick, tracknoactflag endquick = the ticks elapsed = (endquick-startquicktick)/60.0 put elapsed into member "howquick" -- check what the current lowest is -- word 2 of member "lowest" text lowest= xxxx -- if new one is less than (<) old number replace it z1 = member ("lowest").text z = word 2 of z1 if elapsed < z then put elapsed into word 2 of member "lowest" beep 3 end if -- start keeping track of last action tracknoactflag = 1 end on sincelastclick -- this called by all frame scripts -- calls the function the lastclick -- which tells how many ticks since last click -- puts it into text variable q1 -- then puts it into member global tracknoactflag if tracknoactflag = 1 then put the lastclick/60.0 into q put "Hurry Up" && q && "seconds since last click" into q1 put q1 into member "noclick" -- make width of box grow as waiting for action -- multiply by 5 so bigger sprite(9).width = (q*5) + 10 end if end