Results 1 to 4 of 4

Thread: Need a better way to obtain last card in a deck before deck destruction

  1. #1

    Need a better way to obtain last card in a deck before deck destruction

    Currently, if you draw all the cards from a deck, a deck is automatically destroyed when it gets down to the last card. This is not ideal for scripting when you need that last card.

    I've tried a few different solutions, storing the GUIDs of the deck's contents to try and reference the last card- but the cards don't really exist until drawn so this doesn't work. I tried spawning a scripting trigger at the location of the deck to try and grab the final card but due to a separate bug those are unable to work with getObjects() calls. The final work around that works is to have a scripting trigger already exist with the deck (and move it with the deck in case users move the deck around) and check that when there's only a card left, but this is not a great solution for a few reasons- users dropping other cards in the zone and parsing contents, lots of extra scripting and work just to get one last card out of a deck, more scripting zones in an already crowded scripting zone game gets tough to read, unreliable timing on deck destruction for scripting purposes.

    The simplest solution (seemingly, anyway) would be to have the deck still exist, even when down to a single card and only be destroyed when the final card is removed or drawn (though that may get a little tricky when attempting to grab the last card with a mouse- are you grabbing the deck or the card?).

  2. #2
    Join Date
    May 2016
    I have nothing against this suggestion, but I can think of a solution to your problem.

    If your script is doing the dealing, every time a card is dealt you can do a check. if #deck.getObjects() == 2 then and have it record the GUID of the last card in the deck. It might be 2 or 1, depending on when you use it. For 2, I would imagine it would be right before you use takeObject or whatnot to deal the card.

    If cards may be manually removed, then you could use onObjectLeaveContainer(container, obj) to do the same check if the container was that deck. Should alert you to when the deck is going to cease existing and let you pull the card.

    Another solution I like is having a deck zone with a scripting zone, and any time you go to deal it does a check for a deck there and then a card. So if there's a deck it uses it then stops. If there isn't but there's a card it deals the card. And if both fail then it broadcasts that there are no more cards.

  3. #3
    Join Date
    Sep 2016
    The way I solved this was to listen for the onObjectDestroyed event for the deck. Then I would check for all objects within 0.001 distance of where the deck is and store that card as the last one. The 0.001 distance is arbitrary and I haven't done any testing to find out exactly how close the card is during this frame, but it has worked for me 100% of the time when the card is drawn off of a stationary deck. Not sure if it will work under other circumstances.

    But I do agree that the API should be improved to handle this situation without any hacks.

  4. #4
    I really like the onObjectDestroyed solution, its a much cleaner work around for now. Thanks for the ideas and fast responses!

Similar Threads

  1. need help about top card in deck
    By Andrew_Jacop in forum Scripting
    Replies: 2
    Last Post: 03-03-2017, 04:17 AM
  2. Replies: 1
    Last Post: 11-10-2016, 06:05 PM
  3. Avoiding Deck Destruction
    By LordAshes in forum Scripting
    Replies: 3
    Last Post: 07-09-2016, 11:27 PM
  4. Replies: 2
    Last Post: 07-07-2016, 05:15 PM
  5. Replies: 3
    Last Post: 06-02-2015, 07:57 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