Results 1 to 8 of 8

Thread: Detect if a tile has been 吐lipped

  1. #1

    Detect if a tile has been 吐lipped

    What event is triggered by a player using the flip action?
    What property/s show that status?

    Thanks

  2. #2
    Object.is_face_down will tell you if something is roughly face-down. There isn't an event for flipping though.

  3. #3
    Thanks for the answer.

    I’m not sure I want to be repeatedly polling a load of objects to see if they have been flipped since the last time I checked.

  4. #4
    It is not too hard to set up a "flip table" of objects to check, and check at regular intervals.
    Code:
    -- true if object is face down
    flipTable={ objRef1 = true, objRef2 = false, ... , objRefN = true}
    
    function flipCheck()
       for obj, flipped in pairs(flipTable) do
            if obj.is_face_down ~= flipped then
                onObjectFlipped(obj, flipped)
                flipTable[obj] = not flipped
            end
        end
    end
    Wait.time(flipCheck, 0.5, -1) -- check flip state every half second
    if there are a lot of objects, you may need a flag variable to test if the flip check is still running, and start it only when it is not.
    you set the second parameter in the Wait statement as large as appropriate for responsiveness you need. If you need it really fast, like 60 times a second, then do the flip check in onUpdate() instead of managing it with a Wait routine.

  5. #5
    Here's the best solution to solve this problem without using timers or costly events like onUpdate():

    Code:
    -- Object script
    
    function onCollisionEnter(data)
        flipped = last_face_down ~= self.is_face_down
        last_face_down = self.is_face_down
        log(flipped)
    end
    This makes use of the collision event which triggers once when the object hits something else. (After the object is flipped, it has to fall down and hit something again. Therefore, this is the perfect event to use.)

    This method is the most concise and efficient you'll get until a dedicated onFlip() event is implemented.

  6. #6
    Don't forget to register your cards for collisions.

  7. #7
    Quote Originally Posted by cche View Post
    Don't forget to register your cards for collisions.
    With my solution that isn't necessary. Registering collisions only matters if you're using a global collision event like onObjectCollisionEnter().

  8. #8
    Many thanks for all the replies. There is definitely a learning curve to writing & debugging in the TTS environment.
    Below is code that actually reacts the way I want it. I now need to expand & extend the functionality to report more info.

    覧覧覧覧覧覧覧覧覧覧
    Code:
    function onLoad(save_state)
       
        oldFacedown = self.is_face_down
    end
    
    
    function onCollisionEnter(info)
        -- has flipped since game was loaded/item moved etc
        if self.is_face_down ~= oldFacedown then
            oldFacedown = self.is_face_down
            if (self.is_face_down) then
                print(self.getName() .. " is Spent")
            else
                print(self.getName() .. " is Fresh")
            end
        -- this else clause can be commented out. used for testing/debugging
        else
                print(self.getName() .. " has not changed flip status")
        end
    end

Similar Threads

  1. [CONNECTION ISSUES] Custom model freaks out when it's flipped
    By Jhonmikcy in forum Technical Support
    Replies: 1
    Last Post: 08-19-2019, 06:28 PM
  2. [SUPPORT] Custom model freaks out when it's flipped
    By Ninkami in forum Technical Support
    Replies: 0
    Last Post: 07-11-2017, 02:37 PM
  3. Detect clicks on a counter
    By HUECTRUM in forum Scripting
    Replies: 3
    Last Post: 12-18-2016, 08:07 PM
  4. How to detect color?
    By Troubled Salmon in forum Scripting
    Replies: 5
    Last Post: 11-07-2016, 10:46 PM
  5. [ADDED] [v7.7] Hide Description text for Notecards when flipped over.
    By TheRaven81 in forum Suggestions
    Replies: 4
    Last Post: 08-06-2016, 01:40 AM

Tags for this Thread

Posting Permissions

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