A
Arilyn
Guest
Hello,
I'm pretty new to game maker but I've messed around with Unity a lot in the past.
I've hit a roadblock and haven't been able to figure out why I'm getting errors despite researching and reading the documentation, but it's probably because I don't quite understand how GML and scripts work.
I'm creating a card game, and I'm trying to use a DS list to store certain IDs of cards to reference them later. I've created a "DrawCards" function to create instances of the Card object and assign their card_id variable to that of the card drawn.
Here is the code for my playerDeck create event. I add 3 cards to the deck and 3 sprites to a sprite list to keep them lined up with card ids so I can load the front images in the future. After that, I create the hand object.
The hand object runs the following code on the create event.
And then, here's the DrawCards function I was making:
So the problem is when it hits the
Is this something to do with variables in scripts/functions? How can I work around this? Thanks in advance.
edit: fixing formatting
I'm pretty new to game maker but I've messed around with Unity a lot in the past.
I've hit a roadblock and haven't been able to figure out why I'm getting errors despite researching and reading the documentation, but it's probably because I don't quite understand how GML and scripts work.
I'm creating a card game, and I'm trying to use a DS list to store certain IDs of cards to reference them later. I've created a "DrawCards" function to create instances of the Card object and assign their card_id variable to that of the card drawn.
Here is the code for my playerDeck create event. I add 3 cards to the deck and 3 sprites to a sprite list to keep them lined up with card ids so I can load the front images in the future. After that, I create the hand object.
GML:
global.playerDeck = ds_list_create();
ds_list_add(global.playerDeck, 1, 2, 3);
deckCount = ds_list_size(global.playerDeck);
global.sprList = ds_list_create();
ds_list_add(global.sprList, spr_FrontTest1, spr_FrontTest2, spr_FrontTest3);
global.handObj = instance_create(800, 1400, obj_Hand)
GML:
handCount = 0;
global.hand = ds_list_create();
DrawCards(3);
GML:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function DrawCards(_count)
{
for (i = 0; i < _count; i++)
{
var _obj = instance_create(500, 500, obj_Card);
//if the first card in the deck exists
if (!is_undefined(ds_list_find_value(global.playerDeck, 0)))
{
//set the card id to that of the first card in the player deck.
_obj.card_id = ds_list_find_value(global.playerDeck, 0);
//add the card to the end of the hand.
ds_list_add(global.hand, ds_list_find_value(global.playerDeck, 0));
//print the card id
show_debug_message(_obj.card_id);
//move all cards up one slot and remove the last card left behind.
s = ds_list_size(global.playerDeck);
for (_i = 0; _i < s; _i++)
{
if (is_undefined(global.playerDeck, _i + 1))
{
ds_list_delete(global.playerDeck, _i);
}
else
{
ds_list_replace(global.playerDeck, _i, ds_list_find_value(global.playerDeck, _i + 1));
}
}
}
else
{
//Reshuffle the deck.
}
//repeat until the total number of cards is drawn.
}
}
var _obj = instance_create(500, 500, obj_Card);
it gets an error but I don't quite understand why. In addition, when I comment out the instance_create line, it gets another error at the if (ds_list_find_value(global.playerDeck, _i + 1) == undefined)
that says global variable name 'playerDeck' index (100005) not set before reading it.Is this something to do with variables in scripts/functions? How can I work around this? Thanks in advance.
edit: fixing formatting
Last edited by a moderator: