Apps Home
|
Create an App
magic number
Author:
tolender
Description
Source Code
Launch App
Current Users
Created by:
Tolender
/* Magic Number by remmbermytitans */ // vars var total_tipped = 0; var last_tip_username = null; var high_tip_username = null; var high_tip_amount = 1000; var low_tip_username = null; var low_tip_amount = 9; var last_tip_username = null; var last_tip_amount = 0; var numberGuessedCorrectly = false; cb.settings_choices = [ {name: 'Magic_Number', type: 'int', minValue: 10, maxValue: 1000}, {name: 'Prize', type: 'str', minLength: 1, maxLength: 511, default: "Private show"} ]; // handlers cb.onTip(function(tip) { total_tipped += tip['amount'] last_tip_user = tip['from_user'] if (tip['amount'] == cb.settings.Magic_Number) { last_tip_username = tip['from_user'] numberGuessedCorrectly = true } 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'] } high_tip_username = tip['from_user'] high_tip_amount = tip['amount'] } 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'] } 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 Low End Guess:', 'row2_value': format_username(low_tip_username) + '(' + low_tip_amount + ')', 'row3_label': 'Closest High End Guess:', '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 magic number." + " Current Low Number: " + low_tip_amount + "." + " Current High Number: " + 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.