Pipeline Question

T

Toxicosis

Guest
I'm having some problems.

Basically, on my destroy event for an instance, I had it discard all tiles that were associated with it. Whether it had tiles associated with it or not depended on a variable, tiling, which was called during the destroy event.

However, that variable was initialized during the create event. I made now a script during the same create event, which destroys other instances of the same object if they are adjacent and can be replaced by an enlarged version of the calling instance. So, basically, it replaces other bricks if they are too close by stretching itself over their space.

However, during the destroy event, the tiling variable is not set, which causes a crash on running. I don't understand what's going on. Supposedly, as soon as those bricks were placed in the room, they'd have their create event run, and the variable in question is initialized during the create event.

Even placing tiling = 1 in the start of the create event returns a tiling not set error. This is odd. I can already think of a workaround, but in the meantime, I'd like to know your thoughts. I literally set that variable first thing in the create event, and there is nothing that ought to remove it.

Code:
//CREATE EVENT:
tiling = true;
obj_break_hard_create();
scr_brick_economize();

//DESTROY EVENT:
tile_discard();

//TILE_DISCARD:
if tiling = false exit;
var crn_tile;
var max_tile;
max_tile = array_length_1d(tileedge);
for (crn_tile = 0; crn_tile < max_tile; crn_tile++)
{
if tile_exists(tileedge[crn_tile])
  {
  tile_delete(tileedge[crn_tile]);
  }
}

//ERROR MESSAGE:
Variable obj_brick_economic.tiling(100209, -2147483648) not set before reading it.
 at gml_Script_tile_discard (line 1) - if tiling = false exit;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_tile_discard (line 1)
called from - gml_Object_obj_brick_economic_DestroyEvent_1 (line 1) - tile_discard();
 

Bingdom

Googledom
Firstly, your variable comparison is wrong, you should use if tiling == false.
Just a quick tip, you can initialize local variables like this: var crn_tile, max_tile;

Also, you may want to look at event_inherited() if the object is a child of another object
 
W

whale_cancer

Guest
Firstly, your variable comparison is wrong, you should use if tiling == false.
Just a quick tip, you can initialize local variables like this: var crn_tile, max_tile;

Also, you may want to look at event_inherited() if the object is a child of another object
It's my understanding that Studio no longer cares if you use = or == for comparisons.

= - Used to assign a value to a variable. Note that this can also be used for comparing variables in GameMaker: Studio and you may see this in examples and other peoples codes. However, this is a legacy from old GameMaker versions and you should use the == operators for comparing and = for assigning
 
T

Toxicosis

Guest
It is the child, but it doesn't inherit any actions from its parents. It's part of obj_wallz[sic... I didn't think I'd stick with this prototype so long XP]. As for the = and ==, it was working fine, otherwise, I'd have found it back when the thing was working. I'm just surprised things are being destroyed before being created.

MY CURRENT WORKAROUND:

Code:
if !instance_exists(obj_not_done_yet) instance_create(x,y,obj_not_done_yet);
with obj_not_done_yet blocks_counted += 1;

...
with obj_not_done_yet if blocks_counted == blocks_total
{
 with obj_brick_economic obj_break_hard_create();
 instance_destroy();
}

DESTROY CODE:
if !instance_exists (obj_not_done_yet)
 scr_tile_discard();
 
Last edited by a moderator:
W

whale_cancer

Guest
So I would throw a debug message after you set tiling to true. That way we know if it isn't being set or it is being set but then later destroyed.
 
T

Toxicosis

Guest
I don't know how to set a debug message, but there is nothing in the code that would eliminate variables. As far as I understand, it is impossible to do so except by eating the whole instance.

My fix didn't work. I'm gonna try with a 3-step process.

1. Create the instance. Every instance will give an aye to obj_not_done_yet, which will count the instances after every aye. Once it has one aye for every instance,
2. with obj_not_done_yet, use a with loop to make every instance delete the supernumerary instances.
3. After the with loop, tile.

EDIT: Turns out, this one works. XP
 
Last edited by a moderator:
Top