A little help with "tokens" in my card game?

As you maybe would know (or not?) some card games has a mechanic known as tokens. Tokens are "cards" that are generated by other cards, and don't form part of the main deck of cards. That means, after a duel where you used tokens end, the tokens are not shuffled back to the main deck.

With the card game script I have managed so far to create some token mechanics and these are working perfectly.

First, the main script comes with 3 simple categories for cards:
Type, Rarity, and Element which is determined by the element you pick in the database for that skill damage.

Now, I managed to make more categories by myself, like Level, Subtype, Archetype, etc.
One of these categories is called "Frame". I use it to identify cards with special frames like (if you have played yugioh) Synchros, Fusion, and tokens.

After creating this categorie, I find the lines that interact with the cards and managed to create the exception of "tokens" for them. Tokens in yugioh cannot go to the graveyard or banish. So I found the lines what send a card to the graveyard upon use:
Ruby:
  #-----------------------------------------------------------------------------
  # Evaluates card effects and puts the stack to the grave (alias)
  #-----------------------------------------------------------------------------
  alias pc27_cardgame_scenebattle_use_item                              use_item
  def use_item
    pc27_cardgame_scenebattle_use_item
    if @subject.is_a?(Game_Actor)
      effect_name = @subject.current_action.item.impact
      invoke_card_impact(effect_name) if effect_name
      @subject.grave += @subject.stack unless @subject.current_action.item.frame == 5
      @subject.stack = []
      restore_taken_cards(:proceed)
    end
  end

and the line that send cards to the graveyard/banish when you "take" them:
Ruby:
  #-----------------------------------------------------------------------------
  def select_cards_ok_take
    if @card_select_window.cards.size == 0
      select_cancel
      return
    end
    card = @card_select_window.item
    @temp_effect_data[3] = [] unless @temp_effect_data[3]
    @temp_effect_data[3].push(card) unless @card_select_window.item.frame == 5
    @card_select_window.cards.delete_at(@card_select_window.cards.index(card))
    @temp_effect_data[2] += 1
    if PC27::CG::CARD_EFFECT[@temp_effect_data[1]][6] != @temp_effect_data[2]
      @card_select_window.refresh
      @card_select_window.activate
    else
      proceed_selection
    end
  end

and make an exception for tokens, so they technically dissapear (as far as I tested).
(Tokens are Frame 5, so you will notice the exception is item.frame == 5 in both cases).

But after all that, I hit a wall here. When a battle ends, there's a code that take all cards in the graveyard, hand, and banish and shuffle them back to the deck, so they will keep existing in the next battle:
Ruby:
  #-----------------------------------------------------------------------------
  # Restore deck at the end of battle (new)
  #-----------------------------------------------------------------------------
  def on_battle_end
    @deck += @hand + @grave + @banish
    @hand, @grave, @banish = [],[],[]
    super()
  end

So I tried to use the same syntax that I have being using so far, but I can't manage to get the result.

Ruby:
  #-----------------------------------------------------------------------------
  # Restore deck at the end of battle (new)
  #-----------------------------------------------------------------------------
  def on_battle_end
    @deck += @hand + @grave + @banish unless @card.item.frame == 5
    @hand, @grave, @banish = [],[],[]
    super()
  end

I tried several variations and none of them seem to work.
And maybe I have to add some extra lines to define that @card is what's inside @hand @grave and @banish?

I would link how I have modified the script so far so if someone can check it out to help me, it would be cool, and maybe someone who wants a more "updated" card game script can use it for it own.


Card game script updated by me.
So I tried to use the same syntax that I have being using so far, but I can't manage to get the result.

Ruby:
#-----------------------------------------------------------------------------
# Restore deck at the end of battle (new)
#-----------------------------------------------------------------------------
def on_battle_end
@deck += @hand + @grave + @banish unless @card.item.frame == 5
@hand, @grave, @banish = [],[],[]
super()
end
This is fundamentally wrong. The first line is not evaluated if the card is a token, but that goes for the whole hand, grave and banish pile. On top of it, I would be surprised if @card would have a value at all at that point.

One way would be that of removing any token from the deck once battle ends.

Ruby:
@deck.select! { |card| card.item.frame != 5 }

This removes them locally. If you need more information on the method itself, you can take a look at the documentation here:
Ruby documentation - Array - select

I hope this will help you.
This is fundamentally wrong. The first line is not evaluated if the card is a token, but that goes for the whole hand, grave and banish pile. On top of it, I would be surprised if @card would have a value at all at that point.

One way would be that of removing any token from the deck once battle ends.

Ruby:
@deck.select! { |card| card.item.frame != 5 }

This removes them locally. If you need more information on the method itself, you can take a look at the documentation here:
Ruby documentation - Array - select

I hope this will help you.
Thanks! It did work! But I have to remove the "item". For some reason it wasn't working this time. Just card.frame worked fine.
You're my hero!

Original thread: https://forums.rpgmakerweb.com/threads/a-little-help-with-tokens-in-my-card-game.149972/