I
I suck at videogames
Guest
Hello everyone,
I was making Conway's game of life in game maker studio 2, however, if I try to compile it, something weird happens. It says there's an error in line 6 and 7 of my create event in obj_game (the object I use to update the fields on the board), it says
The create event
The draw event
I was making Conway's game of life in game maker studio 2, however, if I try to compile it, something weird happens. It says there's an error in line 6 and 7 of my create event in obj_game (the object I use to update the fields on the board), it says
the same for line seven. My code is at the bottom of this post. I have no idea what's causing this to happen and I'd really appreciate your help!"Object: obj_game Event: Create at line 6: unknown function or script sprite_width"
The create event
Code:
/// @description Setup the object
// You can write your code in this editor
toDrawSprite = spr_square;
spriteWidth = sprite_width(spr_square);
spriteHeight = sprite_height(toDrawSprite);
sizeOfBoard = 10;
//create the board
for (i = 0; i < sizeOfBoard; i += 1) {
for (j = 0; j < sizeOfBoard; j += 1) {
global.board[j,i] = false;
}
}
//make the "nextBoard"
for (i = 0; i < sizeOfBoard; i += 1) {
for (j = 0; j < sizeOfBoard; j += 1) {
nextBoard[j,i] = false;
}
}
Code:
/// @description Draw and update the field
// You can write your code in this editor
//draw the current board
for(i = 0; i < sizeOfBoard; i += 1) {
for (j = 0; j < sizeOfBoard; j += 1) {
currentField = board[j,i];
toDrawX = j * spriteWidth;
toDrawY = i * spriteHeight;
switch(currentField) {
case true:
draw_sprite(toDrawSprite, 1, toDrawX, toDrawY);
break;
case false:
draw_sprite(toDrawSprite, 0, toDrawX,toDrawY);
break;
default:
break;
}
}
}
//update field for next turn;
for (i = 0; i < sizeOfBoard; i += 1) {
for (j = 0; j < sizeOfBoard; j += 1) {
currentBoard[i,j] = false;
currentField = board[j,i];
surroundingFields = 0;
if(board[j-1,i-1]) surroundingFields += 1;
if(board[j,i-1]) surroundingFields += 1;
if(board[j+1,i-1]) surroundingFields += 1;
if(board[j-1,i]) surroundingFields += 1;
if(board[j+1,i]) surroundingFields += 1;
if(board[j-1,i+1]) surroundingFields += 1;
if(board[j,i+1]) surroundingFields += 1;
if(board[j+1,i+1]) surroundingFields += 1;
if(currentField) {
if(surroundingFields >= 4 /*If field is overpopulated*/ || surroundingFields <= 1 /*If the field dies of solitude*/) nextBoard[j,i] = false;
} else {
if(surroundingFields == 3) nextBoard[j,i] = true;
}
}
}
board = nextBoard;