Trouble with card order in deck + card_id

Game development with Board Game Arena Studio
Post Reply
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Trouble with card order in deck + card_id

Post by Ottoreg »

Hello !

I'm currently on the deck/stock part of the developement of my game and I have 2 main issues :

First : My cards seems to be stored in the database table in a wrong order.
If I understand well the process, I create the cards using the data I stored in the array 'wcards'.
So logicaly the first card in the database should be the card with 'type' = 1 and 'type_arg' = 1 but it's not the case. (see screenshot)
And the cards are stored at a different index every time i start a new game.
I'm probably missing something important but I can't figure out what.

Second : I can't get the card_id when I click on a card. Instead of the card_id I get 'undefined'.
It maybe a problem of scope or I'm not passing the right information in gamedata ?

I tried to find a solution looking into the heart tutorial but I couldn't find where I'm wrong.

Your help would be very appreciated ! :)

Code php

function __construct :

Code: Select all

	$this->weapon_card = self::getNew("module.common.deck");
        $this->weapon_card->init("weapon_card");

function setupNewGame :

Code: Select all

        $wcards = array();

        for($color = 1; $color <= 5; $color++ )
        {
            for($value = 1; $value <= 7; $value++ ){
                $wcards [] = array ('type' => $color, 'type_arg' => $value, 'nbr' => 1);
            }  
        }

        $this->weapon_card->createCards( $wcards, 'deck' );
        $this->weapon_card->shuffle('deck');
        $players = self::loadPlayersBasicInfos();

        foreach($players as $player_id => $player){
            $wcards = $this->weapon_card->pickCards(1,'deck', $player_id);
        }
Code js

function constructor :

Code: Select all

this.playerHand = null;

	this.wcard_width = 69;
	this.wcard_height = 96;
function setup :

Code: Select all

	// player hand
	this.playerHand = new ebg.stock(); // new stock object for hand
	this.playerHand.create(this, $('myHand'), this.wcard_width, this.wcard_height);
	this.playerHand.image_items_per_row = 7; // 7 images per row
	dojo.connect( this.playerHand, 'onChangeSelection', this, 'onPlayerHandSelectionChanged');

	// create card types:
	for(var color = 1; color <= 5; color++){
		for(var value = 1; value <= 7; value++)
		{
			// build card type id
			var card_type_id = this.getCardUniqueId(color,value);
			this.playerHand.addItemType(card_type_id, card_type_id, g_gamethemeurl + 'img/wcards.png', card_type_id);
                }
	}

	// cards in player hand 
	for( var i in this.gamedatas.hand){
		var card = this.gamedatas.hand[i];
		var color = card.type;
		var value = card.type_arg;
		this.playerHand.addToStockWithId(this.getCardUniqueId(color,value),card.id);
	}

	onPlayerHandSelectionChanged: function(){
            var items = this.playerHand.getSelectedItems();
            
            if(items.length > 0){

                if(this.checkAction('playCard', true)){
                    // play a card
                    
               	    console.log("on cardChecked "+card_id);
                    var card_id = items[0].id;
                    
                    this.playerHand.unselectAll();

                }
                else{                
                    console.log("on cardChecked "+card_id);
                    this.playerHand.unselectAll();
                }
            }
        },
Example of 'weapon_card' table :

Image
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Trouble with card order in deck + card_id

Post by Tisaac »

The cards are randomized so that's normal.
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Re: Trouble with card order in deck + card_id

Post by Ottoreg »

by randomized do you talk about "$this->weapon_card->shuffle('deck');"
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Trouble with card order in deck + card_id

Post by Tisaac »

No, I mean the function createCards shuffle its argument before running the INSERT in the DB
User avatar
Benoit314
Posts: 82
Joined: 02 April 2020, 22:12

Re: Trouble with card order in deck + card_id

Post by Benoit314 »

Shuffle will change the location_arg of your cards.

So don't implement any game logic based on the card_id, use Type or Type_arg for that. Just assume you don't know the ID of a specific card. You still have to use card_id to manipulate the deck.
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Re: Trouble with card order in deck + card_id

Post by Ottoreg »

Ok ! Thanks guys I think I understand now ! :]
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: Trouble with card order in deck + card_id

Post by Tisaac »

Benoit314 wrote: 29 April 2021, 14:04 Shuffle will change the location_arg of your cards.

So don't implement any game logic based on the card_id, use Type or Type_arg for that. Just assume you don't know the ID of a specific card. You still have to use card_id to manipulate the deck.
Or just insert them yourself so you can control the IDs. We did that on Santorini for instance.
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Re: Trouble with card order in deck + card_id

Post by Ottoreg »

I was thinking about it too, I'll find out the way that suits best my project :)
Post Reply

Return to “Developers”