Legacy GM trying to index a variable which is not an array error

D

Drago Supremo

Guest
Hi guys,

i'm trying to make a script which stes the tiles of a block of wall based on the sprites stored in its array, but somehow when i call this function on the object the compiler tells me that i' m "trying to index a variable which is not an array".

Each block of wall is built at the start of the room by the object "wall starter"

Here's the pieces of code:

WALL STARTER
Code:
objectToReplicate = instance_place(x, y, all);

replicationList = ds_queue_create();
ds_queue_enqueue(replicationList, objectToReplicate);

while !(ds_queue_empty(replicationList))
{
    objectToReplicate = ds_queue_dequeue(replicationList);
  
    with (objectToReplicate)
    {

        replicate(other);
        if (object_index == obj_ground)
        {
            tileSet(parent_boundaries);
        }

    }
}
SCRIPT REPLICATE
Code:
///replicate
if !(place_meeting(x, y + 1, object_index))
{
    replicated = instance_create(x, y + 16, object_index);
    with (argument0) ds_queue_enqueue(replicationList, other.replicated);
}
if !(place_meeting(x, y - 1, object_index))
{
    replicated = instance_create(x, y - 16, object_index);
    with (argument0) ds_queue_enqueue(replicationList, other.replicated);
}
if !(place_meeting(x + 1, y, object_index))
{
    replicated = instance_create(x + 16, y, object_index)
    with (argument0) ds_queue_enqueue(replicationList, other.replicated);
}
if !(place_meeting(x - 1, y, object_index))
{
    replicated = instance_create(x - 16, y, object_index);
    with (argument0) ds_queue_enqueue(replicationList, other.replicated);
}

SCRIPT TILESET
Code:
///tileSet(sprites, boundaries, animated)

placeUp = advancedCollision(x, y - 1, argument0);
placeDown = advancedCollision(x, y + 1, argument0);
placeRight = advancedCollision(x + 1, y, argument0);
placeLeft = advancedCollision(x - 1, y, argument0);



boardXFactor = placeLeft - placeRight;
boardYFactor = placeUp - placeDown;

tFactor = 4 - boardXFactor - 3 * boardYFactor;

sprite_index = sprites[tFactor];

superiorInstance = instance_place(x, y - 1, argument0);
leftInstance = instance_place(x - 1, y, argument0);

xFactor = 0;

if (leftInstance != noone) && (leftInstance.tFactor == tFactor)
{
    xFactor = leftInstance.xFactor + 1;
}

yFactor = 0;

if (superiorInstance != noone) && (superiorInstance.tFactor == tFactor)
{
    yFactor = superiorInstance.yFactor + 1;
}

rowTiles = 1;

if (tFactor == 4)
{
    rowTiles = sprites[tFactor, 0];
}

image_index = xFactor + yFactor * rowTiles;

image_speed = 0;

[/CODE]

"GROUND BLOCK" CREATE EVENT
Code:
sprites[0] = spr_groundLeftSuperiorCorner;
sprites[1] = spr_groundSuperior;
sprites[2] = spr_groundRightSuperiorCorner;
sprites[3] = spr_groundRight;
sprites[4] = spr_groundInterior;
sprites[5] = spr_groundLeftLowerCorner;
sprites[6] = spr_groundInferior;
sprites[7] = spr_groundRightLowerCorner;
 
Last edited by a moderator:
D

Drago Supremo

Guest
What's the full error?

Also,
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_wallStarter:

trying to index a variable which is not an array
at gml_Script_tileSet (line 15) - sprite_index = sprites[tFactor];
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_tileSet (line 15)
called from - gml_Object_obj_wallStarter_CreateEvent_1 (line 16) - tileSet(parent_boundaries);


Also Thank you for highlighting that error :)
 
D

Drago Supremo

Guest
What's the full error?

Also,
Also it looks like the array doesen't exists at all when the function is called! I don't know if it has something to do with the fact that the create haven't still haven't been executed when the script is called (every script SHOULD be executed during the "wall starter" create event.

The order SHOULD be:
- wall starter creation code ----> replication script on the wall to replicate -------> tileSetting script on the wall to replicate -----> replicate the new walls

I don't know if i have been clear enough:bash:
 

TheouAegis

Member
objectToReplicate = instance_place(x, y, all); replicationList = ds_queue_create(); ds_queue_enqueue(replicationList, objectToReplicate); while !(ds_queue_empty(replicationList))
The opening line of your wall starter code looks to me like the wall starter is adding its clone to the Queue. So the first thing it's going to read potentially from the Queue is itself. And since it does not have Sprites assigned to it, it's looking for its own nonexistent array. Which would then raise the question why is the round object check passing? So to rule out that possibility, I would make sure that the wall starter object is not in any way a child of nor a parent of your ground object or the boundaries object.
 
D

Drago Supremo

Guest
The opening line of your wall starter code looks to me like the wall starter is adding its clone to the Queue. So the first thing it's going to read potentially from the Queue is itself. And since it does not have Sprites assigned to it, it's looking for its own nonexistent array. Which would then raise the question why is the round object check passing? So to rule out that possibility, I would make sure that the wall starter object is not in any way a child of nor a parent of your ground object or the boundaries object.
The object check is passed (i tried putting a simple variable in the create event and then using it instead of using an array) and i get the error that tells me the variable doesn't exists in "obj_ground"
 
Top