Need help changing variables through a "with" statement

jaaldis

Member
Basically I'm trying to create three instances of an object called oShopItems. I'm using a "with" statement to try and externally change the positions of each of these three instances once they are created. The code (using a persistent meta obj) looks like this:

GML:
var shop1 = collision_rectangle(280, 200, 318, 220, oShopItems, true, true)
if shop1 = noone && global.storeClosed = false && (!shopItems) {
var Obj1 = room_instance_add(rStuffPlaceInterior, 300, 211, oShopItems);
with (Obj1)
        {
        DrawHereX = 300
        DrawHereY = 211
        }
    shopItems = true;
}
Within oShopItems "create" event, the code looks like this:

Code:
depth = 100;

shop_item[0] = sBookcase_01
shop_item[1] = sCoffee_Table_01
shop_item[2] = sRug_01
shop_item[3] = sRug_02
shop_item[4] = sCake_01
shop_item[5] = sChair_01
shop_item[6] = sLamp_01
shop_item[7] = sLamp_02
shop_item[8] = sHaunted_Doll_01
shop_item[9] = sTV_01
shop_item[10] = sConspiracy_Board

random_object = shop_item[irandom_range(0,10)]

DrawHereX = 0;
DrawHereY = 0;
And then oShopItems also has a "draw" event which looks like this:

GML:
draw_sprite(random_object, 0, DrawHereX, DrawHereY);
When I change the DrawHereX and DrawHereY values inside the oShopItems "create" event, it works fine. But I want to change it within "var (Obj1)" from within the meta object. Nothing happens when I do this though.
Any help would be greatly appreciated!
 

Yal

šŸ§ *penguin noises*
GMC Elder
vars are temporary variables, so they stop existing when the event ends. This means you can't reuse a value from a previous step (e.g. the index returned by instance_create).

Also, you're looking for instance_create_layer, room_instance_create is meant to be used to modify a different room from the one you're in and doesn't return an instance index (because the instance doesn't EXIST until you go to that room)
 

Reprom

Member
Not sure about this function room_instance_add.
In the manual, there is a description to this "With this function you can add an instance into any room other than the current one". I think that you are not getting correct (or at all) instance_id.

Dont know what version you have but you can try:

instance_create_layer(x, y, layer_id, obj);

-or-

instance_create(x, y, obj);
(if you are using gms1.4)
 
Top