D
DekuNut
Guest
SOLVED!!!!!
this was the issue. I was basing my for loop off a ds_list_size that was getting bigger WITHIN the for loop.
So I have a ds_list of 25 values. I need to transfer those values from the ds_list into my 2d array so I can generate 25 tile objects with values. To do this I have this code:
and at the end of my script I destroy the ds_list.
The problem I'm having is in my draw event, when I read all the tiles in a row, the game gives me an error saying:
All the code in obj_controller: (still need to clean up the code a little.)
Code:
for(i=0; i<(25-ds_list_size(temp))-1; i++) {
ds_list_add(temp, irandom_range(1,3));
}
So I have a ds_list of 25 values. I need to transfer those values from the ds_list into my 2d array so I can generate 25 tile objects with values. To do this I have this code:
Code:
if(generateTiles) {
for(i=0; i<5; i++) {
for(j=0; j<5; j++) {
a_tiles[j, i] = instance_create(j*128, i*128, obj_tile);
a_tiles[j, i].value = ds_list_find_value(temp, 0);
ds_list_delete(temp, 0);
}
}
}
The problem I'm having is in my draw event, when I read all the tiles in a row, the game gives me an error saying:
If I comment out ds_list_delete(), I don't get the error (other gameplay issues arise of course). Before I started including a ds_list in my code, everything was working fine besides a few gameplay issues.DoAdd :1: undefined value
at gml_Object_obj_controller_DrawEvent_1 (line 11) - points += a_tiles[j, i].value;
All the code in obj_controller: (still need to clean up the code a little.)
Create Event:
Step Event:
Draw Event:
Code:
start = false;
randomize();
a_tiles = 0;
points = 0;
zeros = 0;
roomLevel = 1;
min_zeros = 6
max_zeros = noone;
totalZeros = noone;
currentZeros = noone;
generateTiles = true;
global.totalScore = 0;
global.currentScore = 0;
global.priorityFlip = 0;
global.lose = false;
victory = 'VICTORY';
failure = 'FAILURE';
next_round = false;
Step Event:
Code:
//____PRE-ALGOR___
if (next_round) { //Did you finish a level?
with(obj_tile) {instance_destroy()};
next_round = false;
global.totalScore += global.currentScore;
global.currentScore = 0;
roomLevel += 1;
generateTiles = true;
}
if(generateTiles) { //Generate values for the Tiles
max_zeros = 8 + floor(roomLevel div 2);
totalZeros = random_range(min_zeros, max_zeros);
currentZeros = totalZeros;
var temp;
temp = ds_list_create();
for(i=0; i<currentZeros-1; i++) {
ds_list_add(temp, 0);
}
for(i=0; i<(25-ds_list_size(temp))-1; i++) {
ds_list_add(temp, irandom_range(1,3));
}
ds_list_shuffle(temp);
}
//____ALGOR____
if(generateTiles) { //Generate obj_tile with values
for(i=0; i<5; i++) {
for(j=0; j<5; j++) {
a_tiles[j, i] = instance_create(j*128, i*128, obj_tile);
a_tiles[j, i].value = ds_list_find_value(temp, 0);
ds_list_delete(temp, 0);
}
}
}
//____POST-ALGOR____
if(generateTiles) { //Done generating tiles, destroy list
ds_list_destroy(temp);
generateTiles = false;
}
if (global.priorityFlip < 1) { //Did you flip all required tiles?
next_round = true;
}
Draw Event:
Code:
if (generateTiles) exit;
draw_set_font(font0);
draw_set_colour(c_white);
//ROWS - generate text to help figure out values under the tiles
for(i=0; i<5; i++) {
points = 0;
zeros = 0;
for(j=0; j<5; j++) {
points += a_tiles[j, i].value; //ERROR -DoAdd :1: undefined value
if(a_tiles[j, i].value = 0) { zeros+=1; }
}
draw_text((128*5)+64+24, (i*128)+24, points);
draw_text((128*5)+64+24, (i*128)+24+64, zeros);
}
//COLUMNS - generate text to help figure out values under the tiles
for(i=0; i<5; i++) {
points = 0;
zeros = 0;
for(j=0; j<5; j++) {
points += a_tiles[i, j].value;
if(a_tiles[i, j].value = 0) { zeros += 1; }
}
draw_text((i*128)+64+24, (128*5)+24, points);
draw_text((i*128)+64+24, (128*5)+24+64, zeros);
}
Last edited by a moderator: