• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Storing DS_list values in a array

D

DekuNut

Guest
SOLVED!!!!!
Code:
for(i=0; i<(25-ds_list_size(temp))-1; i++) {
        ds_list_add(temp, irandom_range(1,3));
    }
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:

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);
        }
    }
}
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:

DoAdd :1: undefined value
at gml_Object_obj_controller_DrawEvent_1 (line 11) - points += a_tiles[j, i].value;
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.

All the code in obj_controller: (still need to clean up the code a little.)
Create 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:

TheouAegis

Member
Post the full code. Your list pointer is in either a temporary (var temp) or local variable, so that suggests you either populated the list in this same event or in another event in the same instance. So what event do you populate the list in and what event is this code in?

also, are you absolutely positive that your list contains 25 values and not 24 values? Prior to running this code, check what the size of the list is. If you use the debugger in studio, you can view the contents of the list as well to make sure it is the right values being stored in it.

Make sure temp is also pointing to the correct list and not holding value of another list. Perhaps all of those valuables got stored in a different list.
 
D

DekuNut

Guest
SOLVED

as soon as I updated xD

Post the full code. Your list pointer is in either a temporary (var temp) or local variable, so that suggests you either populated the list in this same event or in another event in the same instance. So what event do you populate the list in and what event is this code in?

also, are you absolutely positive that your list contains 25 values and not 24 values? Prior to running this code, check what the size of the list is. If you use the debugger in studio, you can view the contents of the list as well to make sure it is the right values being stored in it.

Make sure temp is also pointing to the correct list and not holding value of another list. Perhaps all of those valuables got stored in a different list.
I don't mind posting all the code. Just need a minute to update the OP. Code Posted!

I've tried making the adding an addition 10 values to the list. I still get the error (I'm only taking the first 25 values off the list so it was an easy debug attempt).

I'm only using one list, so it "shouldn't" be a case of having 2 different lists. This is my first time using data structures though, so I'm sure I'm doing something wrong regardless.

EDIT:

Did some more debugging and some of my tiles are getting undefined values, which leads me to believe the ds_list isn't storing values properly (probably something I'm doing).

Code something be wrong with this part of the code here:
Code:
for(i=0; i<(25-ds_list_size(temp))-1; i++) {
        ds_list_add(temp, irandom_range(1,3));
    }
 

Attachments

Last edited by a moderator:

TheouAegis

Member
Try this for your tiles' code.

Code:
if(generateTiles) {
   for(i=0, k=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 = temp[|k++];
       }
   }
}
 
D

DekuNut

Guest
Try this for your tiles' code.

Code:
if(generateTiles) {
   for(i=0, k=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 = temp[|k++];
       }
   }
}
Can you explain the | in temp[|k++];
 

TheouAegis

Member
It's a list accessor. Just makes some ds_list functions easier to type. No need to write out whole function calls.
 
Top