Results 1 to 4 of 4

Thread: Scripting: takeCardFromDeck does not work if the deck has only 1 card

  1. #1

    Scripting: takeCardFromDeck does not work if the deck has only 1 card

    For example when I have deck of 4 cards and I want to shuffle them, then distribute the cards I can take the first 3 cards with takeCardFromDeck() but when I try to take the last card with the same function I get error message "Object reference not set to an instance of an object". I'm assuming this is because the deck transforms itself to a card when there is only one card left. However I can't even place this last card in the onLoad() function with setPositionSmooth() even though it worked for rest of the cards before the deck transformed. So how can I process the last card in this ghost deck?

  2. #2
    Get a scripting zone over the deck to get the GO itself. Then you can do with the new GO (card) what ever you want. Not very nice but i works ^^

  3. #3
    This is a major issue for me. To go through every card in the deck programatically, without adding extra scripting zones, and without destroying the reference to the deck, requires pre-preparing the deck with two dummy cards at the bottom. The API should be able to cope with decks of one or zero cards, so you can take cards out until the deck is empty, do stuff to them, and then put them back.

    Along similar lines, there appears to be no way of returning a card to a deck programatically. (Hopefully it is there in the API and I just missed it).

    I also could not see a simple way to access the cards in a deck programatically without removing the cards from the deck "physically". This could probably be done by having a scripting zone over the deck, but it would be much better to be to able to write
    cards = deck.getObjects()
    I tried this, in the hope that the deck would be treated like a container, but the API didn't allow it.

    Combining all of these issues means that going through a deck to, say, note the GUID of each card or add a description to each card, requires an extremely hacky approach with dummy cards at the bottom, physically moving individual cards, struggling to put them back into the deck, deleting the original dummy cards, and so on.

    It should require about three lines of script to do a one-line operation on each card in a deck, but instead it is a major exercise. I hope I have simply missed part of the API and there is a way to do these things more easily. Right now it looks like deck management is broken.
    Last edited by Arcuate; 02-29-2016 at 04:59 PM. Reason: typos

  4. #4
    For putting cards back into the deck, it is possible to use the deck.reset() function, but this only works for cards that have not formed into new decks (and it is only useful if you want all single cards to return, not useful for returning specific cards). New decks are formed spontaneously if you put single cards down in the same spot, and each of these new decks appears to be outside the reach of the parent deck's reset function.

    So, to go through a deck to read the guids, for instance, it seems necessary to put each card down in a different location so that the deck (with its two dummy cards) can be reset. Finally, following this, the two dummy cards can be deleted.

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
  •