[riah]
;who are the roommates?
exten => s,1,set(__ROOMMATE[1]=Brad)
exten => s,2,set(__ROOMMATE[2]=Brian)
exten => s,3,set(__ROOMMATE[3]=James)
exten => s,4,set(__ROOMMATE[4]=Jeff)
exten => s,5,set(__ROOMMATE[5]=Marc)
exten => s,6,set(__ROOMMATE[6]=Aubrey)
;for each roommate prompt for a weight
exten => s,7,set(__COUNT=1) ;set roommate counter
exten => s,8,while($[${COUNT}<7]) ;while we havent assigned a weight to all the roommates...
exten => s,9,background(beep) ;prompt with a tone...
exten => s,10,waitexten(5) ;and givem five seconds to enter an extension 0-9
exten => s,11,set(__COUNT=$[${COUNT}+1]) ;then increment the counter
exten => s,12,endwhile
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;take the weight and build the array;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
exten => _X,1,set(__MATEWEIGHT[${COUNT}]= ${EXTEN}) ;give each roommate a relative weight using the counter
exten => _X,n,goto(s,11) ;then repeat
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;after weights are assigned, pick roommates until we have two winners
exten => s,13,set(__WINNERS=0) ;at first we have no winners
exten => s,14,set(__CLEANER[1]=NoOne) ;and we'll use a new counter
exten => s,15,while($[${WINNERS} < 2]) ;while we dont have two winners...
exten => s,16,noop(${CLEANER[1]})
exten => s,17,goto(Brad,1) ;go to an extension based on roommate name below
exten => s,18,goto(Brian,1) ;go to an extension based on roommate name below
exten => s,19,goto(James,1) ;go to an extension based on roommate name below
exten => s,20,goto(Jeff,1) ;go to an extension based on roommate name below
exten => s,21,goto(Marc,1) ;go to an extension based on roommate name below
exten => s,22,goto(Aubrey,1) ;go to an extension based on roommate name below
exten => s,23,noop(END OF THE LOOP. HOW MANY WINNERS? ${WINNERS})
exten => s,24,endwhile
;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
exten => Brad,1,noop(we made it here ${CLEANER[1]}) ;jump to three if we have a winner
exten => Brad,2,random(${MATEWEIGHT[1]},Brad,3) ;jump to three if we have a winner
exten => Brad,3,goto(s,18) ;or else draw again.
exten => Brad,4,gotoif($[ "${CLEANER[1]}" = "Brad"]?3) ;did we just pick him?
exten => Brad,5,set(__WINNERS=$[${WINNERS}+1]) ;if not we have a winner
exten => Brad,6,set(__CLEANER[${WINNERS}]=${ROOMMATE[1]}) ;and we set the CLEANER variable
exten => Brad,7,noop(WE HAVE A WINNER). ;and draw again
exten => Brad,8,goto(s,18) ;and draw again
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;Go to exten ${ROOMMATEN[1-6], and use their weight to "draw" for a "win";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
exten => Brian,1,random(${MATEWEIGHT[2]},Brian,3) ;jump to three if we have a winner
exten => Brian,2,goto(s,19) ;or else draw again.
exten => Brian,3,gotoif($[ "${CLEANER[1]}" = "Brian"]?2) ;did we just pick him?
exten => Brian,4,set(__WINNERS=$[${WINNERS}+1]) ;if not we have a winner
exten => Brian,5,set(__CLEANER[${WINNERS}]=${ROOMMATE[2]}) ;and we set the CLEANER variable
exten => Brian,6,goto(s,19) ;and draw again
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;
;THEN I DO THIS FOR FOUR OTHER ROOMATES AND s,25 IS SUPPOSED TO SPIT OUT WINNERS;
;;;;;;;;;;;;;;;;;;;;;;
exten => s,25,noop(${CLEANER[1]} and ${CLEANER[2]} are the winners.)
;;;;;;;;:THE CLI SAYS;;;;;;;;;;;;;;;
-- Executing NoOp("SIP/Brian-be1d", "END OF THE LOOP. HOW MANY WINNERS? 0") in new stack
-- Executing EndWhile("SIP/Brian-be1d", "") in new stack
-- Executing While("SIP/Brian-be1d", "1") in new stack
-- Executing NoOp("SIP/Brian-be1d", "NoOne") in new stack
-- Executing Goto("SIP/Brian-be1d", "Brad|1") in new stack
-- Goto (riah,Brad,1)
-- Executing NoOp("SIP/Brian-be1d", "we made it here NoOne") in new stack
-- Executing Random("SIP/Brian-be1d", " 9|Brad|3") in new stack
-- Executing Goto("SIP/Brian-be1d", "s|18") in new stack
-- Goto (riah,s,18)
-- Executing Goto("SIP/Brian-be1d", "Brian|1") in new stack
-- Goto (riah,Brian,1)
-- Executing Random("SIP/Brian-be1d", " 9|Brian|3") in new stack
Apr 17 04:46:45 WARNING[2082]: pbx.c:6455 ast_parseable_goto: Goto requires an argument (optional context|optional extension|priority)
-- Random branches to (riah,Brian,2)
== Spawn extension (riah, Brian, 1) exited non-zero on 'SIP/Brian-be1d'
-- Remote UNIX connection disconnected