FATAL ERROR:Variable obj_deckGen.playednot set before reading it.

M

MineEXP23

Guest
So here's my Code Error:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_deckGen:

Variable obj_deckGen.played(100012, -2147483648) not set before reading it.
at gml_Script_scr_card_selection (line 9) - if (played == false) {
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_card_selection (line 9)
called from - gml_Object_obj_deckGen_Step_0 (line 2) - scr_card_selection();

=============================================================================

And here's my script where it says the error is at:
if (ai_turn == false) {
if (mouse_check_button_pressed(mb_left)) {
if (instance_position(mouse_x, mouse_y, obj_card_p)) {
scr_get_top_card();
}
}
if (mouse_check_button(mb_left)) {
with (card_selected) {
if (played == false) {
x = mouse_x;
y = mouse_y;
depth = -room_height;
}
}
} else if (mouse_check_button_released(mb_left)) {
if (card_selected != noone) {
scr_play_card();
with (obj_card_p) {
depth = -start_y
card_selected = noone
}
}
}
}

===============================================================================

Where does it say anywhere in there that there is 'obj_deckGen.played' in there at all?
I can't seem to find it but if anyone can please let me know, i really want to complete my first game in game maker so I can move on to other maybe slightly harder projects.
 
It's telling you where the problem is:
Code:
if (played == false) {
The reason it says "obj_deckGen.played" is because you are calling a script, so the script is referencing the calling instance to check whether the variable played is true or false, however, you haven't created the played variable in the obj_deckGen object, so it's trying to check whether a variable that doesn't exist is true or false, which is why it's throwing you the error. You need to initialise the played variable in the Create Event of obj_deckGen. This is simply done by putting:
Code:
played = false; // Or true, depending on what you want
In the Create Event of obj_deckGen.
 
Top