Results 1 to 4 of 4

Thread: Help on a Javascript (Slot Machine)

  1. #1
    Join Date
    Jul 2010
    Location
    Philippines
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help on a Javascript (Slot Machine)

    Hi to all, I need a little help.
    I'm having a problem deciphering this script.
    This is a 3 image slot machine script(I guess)
    Can someone explain to me how this code works?
    And how can I make it show the same result?

    here it goes:
    var chaosMachineSpinCtr = 0;
    function chaos_machine_attempt(params) {
    params.on_start(params);
    $.post(params.post_url, {}, function(data) {
    var ret = JSON.parse(data);
    spinResults = ret.spin_results;
    chaosMachineSpinCtr = 0;
    chaos_machine_spin_slot(params, ret);
    });

    }

    function chaos_machine_spin_slot(params, ret) {
    spinResults = ret.spin_results;
    if(chaosMachineSpinCtr < 25) {
    $('#'+params.ul_id+' li[rel=1] > img').attr('src', params.images[array_rand(params.images)]);
    } else if(chaosMachineSpinCtr == 25) {
    $('#'+params.ul_id+' li[rel=1] > img').attr('src', spinResults.images[0]);
    }

    if(chaosMachineSpinCtr >= 25 && chaosMachineSpinCtr < 50) {
    $('#'+params.ul_id+' li[rel=2] > img').attr('src', params.images[array_rand(params.images)]);
    } else if(chaosMachineSpinCtr == 50) {
    $('#'+params.ul_id+' li[rel=2] > img').attr('src', spinResults.images[1]);
    }

    if(chaosMachineSpinCtr >= 50 && chaosMachineSpinCtr < 75) {
    $('#'+params.ul_id+' li[rel=3] > img').attr('src', params.images[array_rand(params.images)]);
    } else if(chaosMachineSpinCtr == 75) {
    $('#'+params.ul_id+' li[rel=3] > img').attr('src', spinResults.images[2]);
    }

    chaosMachineSpinCtr++;

    if(chaosMachineSpinCtr <= 75) {
    setTimeout(function() {chaos_machine_spin_slot(params, ret);}, 50);
    } else {
    params.on_end(params, ret);
    }
    }
    <script type="text/javascript">
    $(function() {
    $('#balance_warning').hide();
    $('#start_spinning').click(function() {
    var params = JSON.parse('{"post_url":"\/promo\/chaos_machine2","images":["http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/large_sd_potion.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/wing_of_storm.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/devil_square_ticket_(1_use).jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/bone_blade.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/blood_castle_ticket_(1_use).jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/jewels_of_soul_(stack_of_30).jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/fruit_strength.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/blood_castle_ticket_(10_uses).jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/devil_square_ticket_(10_uses).jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/jewel_of_life.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/gem_stone.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/jewel_of_creation.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/large_complex_potion.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/fruit_energy.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/fruit_stamina.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/fruit_agility.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/swords_knightblade_9_skill_luck_12.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/bows_arrowviperbow_9_skill_luck_12.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/platina_staff.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/swords_darkreign_9_skill_luck_12_exc.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/jewel_of_harmony.jpg","http:\/\/img.mobiusonline.net\/images\/stores\/products\/52x52\/jewel_of_bless.jpg"],"ul_id":"spin_me"}');
    params.on_start = function(params) {
    $('#start_spinning').fadeOut();
    $('#youLose').fadeOut();
    };

    params.on_end = function(params, spinResult) {
    var prodPrice = 20.00;

    $('#remaining_balance').html(spinResult.remaining_balance);
    if(spinResult.awarded == 1) {
    tb_show('Congratulations! You Won!', '/promo/chaos_machine_prize?width=400&height=350');
    } else {
    $('#youLose').fadeIn();
    }

    if(prodPrice > spinResult.remaining_balance) {
    $('#balance_warning').show();
    } else {
    $('#start_spinning').fadeIn();
    }
    };
    chaos_machine_attempt(params);
    return false;
    });
    });
    </script>
    Last edited by Informatics; 08-01-2010 at 05:51 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This sounds a lot like a homework problem, and that's not really why we're here. If that's not the case, explain a bit more.
    And why don't you understand the code? Is it not yours?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    There must be more to it, because "$" is used over and over, and isn't defined in any way. Sometimes people might make "$" a function like this:

    Code:
    $ = function() { }
    Oh... I just figured out that this uses JSON. If you don't know what JSON is, or how to use it, there's no point to try to understand this code.
    - Mike

  4. #4
    Join Date
    Jul 2010
    Location
    Philippines
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    @drj33 It's not an assignment sir dj, I was just trying to understand it.

    @mburt I edited it sir, added a new quote with the "$" function. Is this what you mean?

    Thank you for your replies.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •