the_dude_abides
Member
Hi.
I am trying to set up an object so that, if it falls under certain conditions, it has certain pieces of information already stored under local variables when accessed later in a for loop by another object.
The idea is that, rather than a lot of calls for a permanent variable, it has it beforehand within the event, and presumably is less costly.
I can get this to work in part, but for some reason it only works with one instance. You can ignore most of the code, as it's basically seeing if two rectangles are in contact. I can see when they are active, as I've set them to change colour.
It is getting the local variable of 'self_path', but only one instance is responding to it. I can see that there are others "active", as their colour changes from the "image_blend = c_black" code, but only one ends up doing their code for the path (creating an object along the path to make the results visible)
It seems to have the local variable held when accessed later, but goes wrong after that. Any ideas why?
I am trying to set up an object so that, if it falls under certain conditions, it has certain pieces of information already stored under local variables when accessed later in a for loop by another object.
The idea is that, rather than a lot of calls for a permanent variable, it has it beforehand within the event, and presumably is less costly.
I can get this to work in part, but for some reason it only works with one instance. You can ignore most of the code, as it's basically seeing if two rectangles are in contact. I can see when they are active, as I've set them to change colour.
Code:
with (is_mine)
{
was_bullet_coll = true;
single_path_pos = floor(path_position * single_path_num);
if bbox_bottom > cur_top
{
var side_top = y - radius;
var side_bot = room_height;
var side_left = self_left_side;
var side_right = self_right_side;
var self_volume = side_right - side_left * (side_bot - side_top);
var min_vol = min(self_volume, other_volume);
switch (min_vol)
{
case self_volume:
var min_left = side_left;
var min_top = side_top;
var min_right = side_right;
var min_bot = side_bot;
var max_left = new_left;
var max_top = new_top;
var max_right = new_right;
var max_bot = new_bot;
break;
case other_volume:
var min_left = new_left;
var min_top = new_top;
var min_right = new_right;
var min_bot = new_bot;
var max_left = side_left;
var max_top = side_top;
var max_right = side_right;
var max_bot = side_bot;
break;
}
if rectangle_in_rectangle(min_left, min_top, min_right, min_bot, max_left, max_top, max_right, max_bot)
{
was_bullet_coll = false;
var self_path = mine_path;
}
}
}
for (var path_point = is_bullet_step; path_point < bullet_path_num; path_point++)
{
path_x = path_get_point_x(bullet_path, path_point);
path_y = path_get_point_y(bullet_path, path_point);
instance_create(path_x,path_y, obj_pointer);
new_left = path_x - is_bull_width;
new_top = path_y - is_bull_width;
new_right = path_x + is_bull_width;
new_bot = path_y + is_bull_width;
with (is_mine)
{
if !was_bullet_coll
{
image_blend = c_black; <<<< I can see this happening
new_path_pos = single_path_pos + path_point;
if new_path_pos < single_path_num
{
is_point_x = path_get_point_x(self_path, new_path_pos);
is_point_y = path_get_point_y(self_path, new_path_pos);
instance_create(is_point_x, is_point_y, enemy_mine); <<<< Only happens for one instance. Works with all (that it should) if they call the path through the stored variable, and not the local one
}
if rectangle_in_circle(new_left, new_top, new_right, new_bot, is_point_x, is_point_y, self_radius) != 0
{image_blend = c_red;
other.do_left_mine = true;
was_bullet_coll = true;
}
}
}
}
It seems to have the local variable held when accessed later, but goes wrong after that. Any ideas why?
Last edited: