Results 1 to 3 of 3

Thread: What is the best way of monitoring obj.resting?

  1. #1
    Join Date
    Jun 2017
    Location
    Sweden
    Posts
    24

    What is the best way of monitoring obj.resting?

    The sort version:
    I want to generate an event when resting == true for a number of dices.

    What are the best way of implementing it?
    Is it possible to do without having an onUpdate function?

  2. #2
    Join Date
    May 2016
    Posts
    1,072
    Code:
    --This makes a blank table used later
    ref_diceWatched = {}
    
    --Watch for randomized dice (hitting R on them)
    function onObjectRandomize(object, player_color)
        if object.tag=="Dice" and ref_diceWatched[object]==nil then
            ref_diceWatched[object] = true
            watchDieRoll(object, player_color)
        end
    end
    
    --Watch for dropped dice (physically rolled) (possible cheat warning)
    function onObjectDropped(player_color, object)
        if object.tag == "Dice" and ref_diceWatched[object]==nil then
            ref_diceWatched[object] = true
            watchDieRoll(object, player_color)
        end
    end
    
    --Function which runs a coroutine to watch the dice
    function watchDieRoll(die, color)
        function watchDieRoll_routine()
            while die.resting == false do
                coroutine.yield(0)
            end
    
    
    
            ref_diceWatched[die] = nil
            return 1
        end
        startLuaCoroutine(Global, "watchDieRoll_routine")
    end
    He is one I wrote a while back. Those 3 empty lines in the watchDieRoll function are where you would insert any code you want to have ru nonce the dice come to rest.

  3. #3
    Join Date
    Jun 2017
    Location
    Sweden
    Posts
    24
    It might work for me... but it doesn't seem like it handels when a dice get velocity form sources other than a player.
    Could that not pose a problem when rolling multiple dice at once?

Similar Threads

  1. resting(set)
    By TattleTale in forum Scripting
    Replies: 1
    Last Post: 02-03-2017, 06:04 PM
  2. Change to resting variable behavior
    By mkanoap in forum Scripting
    Replies: 1
    Last Post: 06-09-2016, 08:18 PM

Posting Permissions

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