VGMQ: SCRIPTED QUIZ

The my-event editor already provides many special features you can use to create a custom experience.

With the scripted quiz, you can now define your own re-usable specials in javascript!

It also gives you more control over the quiz, and enables conditional specials through the use of player variables

DEMO SPECIALS

BASE SCRIPT


function quiz($quiz, $player, $scope, $room, $chat, $me, $timeout){

	$scope.categories = ['rpg','sport','strategy','action'];
	$scope.selectCat = c => {
		$scope.myCat = c;
		$player.set('cat',c);
	}

	$quiz.on('init',()=>{
		// the quiz is ready, after it is launched or player join/F5 during                
		// we restore player variables needed in html scope
		$scope.myCat = $player.get('cat');
	});    

	$quiz.on('round-start',o=>{
		console.info('ROUNDSTART',o.current,o);
		if(o.current===1) $chat.warn('This is the first round');    		
	});

	$quiz.on('intro',()=>{
		$chat.warn('The intro STARTED');
	});

	$quiz.on('outro',()=>{
		$chat.warn('The outro STARTED');
	});

	$quiz.on('destroy',()=>{
		// remove eventual service listeners...        
	});
	
	
}
			

TEMPLATE


<div class="my-super-quiz" >
    <b ng-if="myCat">YOUR CATEGORY: {{myCat}}</b>
    <div ng-if="!myCat">
        <span ng-repeat="c in ::categories">
            <button ng-click="selectCat(c)">{{::c}}</button>
        </span>
    </div>
</div>
			

CSS


#quiz .my-super-quiz button {
	color:red;
}
			

OTHER SAMPLES

GLOBAL VARIABLES

Some use cases can't be implemented with storing variables only on players. A more general set of variables globally shared by all players is available, and is known as the quiz "bag".
Because server-side scripting is not possible, creators should adapt their concept so the logic runs on the client and uses these shared variables to simulate server needs.
ALL VARIABLES ARE STORED AND RETRIEVED AS STRINGS. (except $quiz.inc() which returns an int)


// set shared variable
$quiz.set('varname','hello world');
let v = $quiz.get('varname');

// increment shared variable
let v = $quiz.inc('counter'); // WARNING: not atomic

// iterate all variables
let bag = $quiz.getBag();
for(let k in bag){
	console.info(k, bag[k]);
}

// listen to variable change
$quiz.on('bag-varname',o=>{
	console.info('varname has changed',o);
	// WARNING: never change global variables here
	// or it will start endless event loop
});

// listen to any variable change
$quiz.on('bag-*',o=>{	
	// WARNING: never change global variables here
	// or it will start endless event loop
});
			

You can check these variables in conditional specials by prefixing them with the hash # symbol