Results 1 to 3 of 3

Thread: Question about OneLivesLeft's Wait Code....

  1. #1

    Question about OneLivesLeft's Wait Code....

    Quote Originally Posted by onelivesleft View Post

    I'll do you an upgrade, related to this post.

    function after(delay, func, ...)
        local params = {...}
        function after_routine()
            if type(delay) == 'function' then
                repeat coroutine.yield(0) until not delay()
                local after_time = os.clock() + delay
                repeat coroutine.yield(0) until os.clock() >= after_time
            return 1
        startLuaCoroutine(self, 'after_routine')
    Does what the last one did, but can also take a function as the delay parameter; it triggers after the function stops being true.

    So for instance, you can:

    -- die is the die object
    die.setPositionSmooth({1, 2, 3})
    after(die.isSmoothMoving, die.roll)

    Bit confused about this... say I am doing a "deal" function... (im using a custom function called getTag here to find teh card or deck in a script zone.

    function deal2Players()
        for k, v in pairs (getTag(getObjectFromGUID('517717'), 'Deck', 'Card')) do
            if v.tag == 'Deck' then
                for k, p in pairs(getSeatedPlayers()) do
          , p)
    How would I use the above function to do something AFTER the deal is completed? (That is what his code dose right?)

    Or if I wanted to destroy a setup object after setup.. how would I use his code to destroy AFTER all the setup stuff is completed?
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  2. #2
    It needs either a time value, or a function that stops returning true after some time.

    With deal(), we don't have a callback available and the time it takes is not constant. But you could approx it by e.g. amount of cards dealt times 0.2s or whatever and just use after(0.2*6, stuff).
    Or you could create a function that counts cards in player hands and if would return false when those 6 dealt cards are in there.

    Same with your setup. If you can determine when it ends - let's say some deck is spawned last - you construct a function that checks for its (non)existence and load it to after() so it fires after it is created and function returns false.
    But in case of complex situations, I'd advise more custom solutions that just trying to wrap it around a general use after().

  3. #3
    If I'm reading your code right, then you're only ever dealing from one deck? i.e. the first 'for' loop is looping over objects in a zone, but it's only supposed to find one deck? If so, you can do it like this:

    function deal2Players()
        local cards_to_deal = 6
        local deck = first_deck_in_zone(getObjectFromGUID('517717'))
        local target_cards = deck.getQuantity() - (cards_to_deal * total_players())
        if target_cards < 0 then target_cards = 0 end
        after(function() return deck.getQuantity() > target_cards end, function_you_want_to_call_afterwards)
        for k, p in pairs(getSeatedPlayers()) do
  , p)
    function function_you_want_to_call_afterwards()
    function first_deck_in_zone(zone)
        for i, object in pairs(zone.getObjects()) do
            if object.tag == "Deck" then
                return object
        return nil
    function total_players()
        local total = 0
        for k, p in pairs(getSeatedPlayers()) do
            total = total + 1
        return total
    Though note this will trigger as soon as the last card has left the deck; it may not have reached the player's hand yet.

Similar Threads

  1. Replies: 2
    Last Post: 01-21-2017, 06:37 PM
  2. No longer need to wait after spawning an object?
    By Kalazor in forum Scripting
    Replies: 2
    Last Post: 08-16-2016, 02:47 PM
  3. Wait X Frames until deck completes? :D
    By se7en in forum Scripting
    Replies: 5
    Last Post: 04-25-2016, 04:13 PM
  4. Replies: 1
    Last Post: 01-30-2015, 01:09 AM
  5. Can't wait to play!
    By darkknifer in forum General Discussion
    Replies: 1
    Last Post: 02-12-2014, 11:23 AM

Posting Permissions

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