Apps Home
|
Create an App
Guess The Number
Author:
adventurouscouple
Description
Source Code
Launch App
Current Users
Created by:
Adventurouscouple
/* Guess the Number by AdventurousCouple using source code provided by: Magic Number by remmbermytitans Changes: Coding changed to correctly update Over and Under values as they approach the correct guess number. There was an issue causing the last tip to be updated, whether it was closer or further from the actual answer. Also changed some wording to sound less confusing. */ // vars var total_tipped = 0; var last_tip_username = null; var high_tip_username = null; var high_tip_amount = 100; var low_tip_username = null; var low_tip_amount = 10; var last_tip_username = null; var last_tip_amount = 0; var numberGuessedCorrectly = false; cb.settings_choices = [ {name: 'Magic_Number', type: 'int', minValue: 10, maxValue: 100}, {name: 'Prize', type: 'str', minLength: 1, maxLength: 511, default: "5 Minute Private show"} ]; // handlers cb.onTip(function(tip) { total_tipped += tip['amount'] last_tip_user = tip['from_user'] //Guess Number if(tip['amount'] == cb.settings.Magic_Number) { last_tip_username = tip['from_user'] numberGuessedCorrectly = true } //Guess Over Number else if(tip['amount'] > cb.settings.Magic_Number){ if(tip['amount'] < high_tip_amount){ high_tip_amount = tip['amount'] high_tip_username = tip['from_user'] } else{ high_tip_amount = high_tip_amount high_tip_username = high_tip_username } } //Guess Under Number else if (tip['amount'] < cb.settings.Magic_Number) { if(tip['amount'] > low_tip_amount){ low_tip_amount = tip['amount'] low_tip_username = tip['from_user'] } else{ low_tip_amount = low_tip_amount low_tip_username = low_tip_username } } else{ last_tip_username = tip['from_user'] last_tip_amount = tip['amount'] } update_App(); cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tips Received:', 'row1_value': total_tipped, 'row2_label': 'Closest Guess Below Number:', 'row2_value': format_username(low_tip_username) + '(' + low_tip_amount + ')', 'row3_label': 'Closest Guess Over Number:', 'row3_value': format_username(high_tip_username) + '(' + high_tip_amount + ')' }; }); // helper functions function update_App() { if (numberGuessedCorrectly == true) { var new_subject = "We have a winner!. " + last_tip_username + " has guessed the correct number, " + cb.settings.Magic_Number + "! \nThe winner gets: " + cb.settings.Prize + "."; } else { var new_subject = "Guess the number." + " Current Guess Below: " + low_tip_amount + "." + " Current Guess Above: " + high_tip_amount + "." + " \nThe winner gets: " + cb.settings.Prize + "."; } cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject) } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function init() { update_App(); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.