-
Notifications
You must be signed in to change notification settings - Fork 242
Closed
Description
I needed a way to set the randomizer return value after each spin via AJAX (I'm using PHP to prevent client side injection). I was able to add a new function that accepts the index of the chosen element... maybe there's a better way but here's a snippet of my solution.
/**
* @desc PRIVATE - Updates the index to the new custom value
*/
function _updateCustom(indexToSet){
_active.index = indexToSet;
}
/**
* @desc PUBLIC - SET chosen element
*/
setCustom : function(indexToSet){
if(typeof indexToSet==='number' && indexToSet>=0 && indexToSet<$titles.length){
_updateCustom(indexToSet);
}
}
Then I did something really bad with the _getCustom() private function:
I changed var index = self.settings.randomize(_active.index);
to just var index = _active.index;
And then my usage was simply:
$("#pull").click(function() {
$.ajax({
url: 'ajax/slotmachine_ajax_responder.php',
type: 'POST',
data: {'method': "spin"},
dataType: 'json',
cache: false,
success: function(data) {
if (data.success) {
//Set finishing placements
machine1.setCustom(data.num1);
machine2.setCustom(data.num2);
machine3.setCustom(data.num3);
//Do the spinning
machine1.shuffle(3, onComplete);
setTimeout(function() {
machine2.shuffle(3, onComplete);
}, 250);
setTimeout(function() {
machine3.shuffle(3, onComplete);
}, 500);
}
}
});
});
Please let me know where I can improve on this. Thanks!
Metadata
Metadata
Assignees
Labels
No labels