SOLVED What am i doing wrong here

creating instances and what to get the sprite in rows of 3 but this keeps shooting a crash

for (var texture_index = 0; texture_index < texture_size; texture_index += 1) {
for (var row = 0; row < 3; row += 1){

var texture = global.texture[ | (texture_index*3)+row]


ERROR
ds_map_find_value argument 1 incorrect type (undefined) expecting a Number (YYGI32)
 
I don't think that is where the bug is. It's saying ds_map_find_value, but you've only got a list there. Is there anywhere else you are trying to pull something out of a map?
 
I apologize that i wasnt clear. Super tired

The issue is in the var texture line.
If I change it to texture_index+row there is no issue at all.
But if its texture_index×3+row the crash comes up
 

TsukaYuriko

🌠
Forum Staff
Moderator
It is technically not feasible for this code to spawn this error message. The error message mentions a map, you are not using a map in the code you've shown.

Please post the full code.
 
GML:
for (var texture_index = 0; texture_index < texture_size; texture_index += 1) {   
    for (var row = 0; row < 3; row += 1){
        
        var texture = global.texture[| texture_index*3+row] <---- this is the only thing i change (texture_index+row) works 
        
        with (instance_create_depth(x,y,depth-9, ob_texture)){
        posX = fleet_x_gap + (2*fleet_x_gap) * row
        posY = ((fleet_size+avatar_size+1)*(fleet_y_offset)) + fleet_x_gap*1.25 + texture_index*fleet_y_offset
        scale = .6   
        name = texture[? "name"]
        sprite = texture[? "sprite"]
        purchased = texture[? "purchased"]
        
MAP       
        
var name = argument0;
var sprite = argument1;
var purchased = argument2;
var active = argument3;
var re_crystal = argument4;
var re_coin = argument5;

var texture = ds_map_create();
ds_map_add(texture, "name", name);
ds_map_add(texture, "sprite", sprite);
ds_map_add(texture, "purchased", purchased);
ds_map_add(texture, "active", active);
ds_map_add(texture, "re_crystal", re_crystal);
ds_map_add(texture, "re_coin", re_coin);

ds_list_add(global.texture, texture);

return texture;

global.texture = ds_list_create();
sc_add_texture("blank", sp_texture_none,0,0,0,0)
sc_add_texture("army", sp_texture_army,0,0,0,0)
sc_add_texture("patt", sp_texture_lg_bw_pattern,0,0,0,0)
 

FrostyCat

Member
You are accessing an entry that doesn't exist in global.texture, thus getting undefined into texture. Several lines later, you try to reference texture[? "name"]. See the problem yet?

Look at your code for setting up the list, then think over what the correct expression for the position is.
 
You are accessing an entry that doesn't exist in global.texture, thus getting undefined into texture. Several lines later, you try to reference texture[? "name"]. See the problem yet?

Look at your code for setting up the list, then think over what the correct expression for the position is.
I not sure wbat tou mean. Name is argument0
 

TsukaYuriko

🌠
Forum Staff
Moderator
argument0 is texture because name = texture[? "name"] is equal to name = ds_map_find_value(texture, "name").
 

TsukaYuriko

🌠
Forum Staff
Moderator
texture itself is a map. Or at least it is being treated like it is a map.

An error is thrown because texture, at the time, holds undefined, yet you are trying to access it like a map.
It is undefined because you tried to access a list element out of bounds, which therefore doesn't exist, hence undefined is returned.
 
i hear what you are saying.
Im going to rebuild the map and check a tutorial or two. and hopefully i can come back and show you a system that works
Is there anything else in the code i need to pay close attention to?

I know this may sound like a brush off, i assure you it isnt. Im thankful that people can help others in this forum
 
If you use the debugger, you can physically check how many items are in the global.texture list while the game is running. Run the game using F6 (or clicking the Debug button next to the normal Run button), then pause the game using the debugger and either set a watch for global.texture or check the Variables tab and right click on global.textures and select View As > ds_list. You can then expand it and see what all the entries are. It might give you a clue as to why it's not the size you think it is.
 

TheouAegis

Member
My question is why are you multiplying by 3? I don't see where in your code global.texture is getting elements added to it in multiples of 3. I see you created 3 textures, so is texture_size 1? With your code that is causing the bug, texture_size would need to be 1/3 the size of global.texture.
 
My question is why are you multiplying by 3? I don't see where in your code global.texture is getting elements added to it in multiples of 3. I see you created 3 textures, so is texture_size 1? With your code that is causing the bug, texture_size would need to be 1/3 the size of global.texture.
the reason for the 3 is because there are 3 instances per row. there are also a lot more than 3 textures but i only copied 3 into the forum to giv example
 
Okay, and what is the size of your list? And what is the value of texture_size?
Currently 13

Edit: oooooh wait maybe because the liat size is not divisable by 3 that its looking for the map stuff for a list item that doesnt exist.

The issue isnt the map its the amount of entries
 
fixed the issue. i was over thinking it and didnt need to put the texture index in the posY at all
thanks for all your help

GML:
row=0
    for (var texture_index = 0; texture_index < texture_size; texture_index += 1) {   
    
        var texture = global.texture[| texture_index]
        row += 1
        if row > 3
        {
            row = 0
            down += 1
        }
  
with (instance_create_depth(x,y,depth-9, ob_texture)){
        posX = fleet_x_gap + (2*fleet_x_gap) * (row -1)
        posY = (fleet_size+round((avatar_size/3))*(fleet_y_offset)) + fleet_x_gap*1. + fleet_y_offset*down
 
Top