• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Find Number of Instances I'm Colliding with, and Their Ids

I'm trying to loop through to find how many collisions with Tree_obj I'm getting in the player's collision rectangle (actually place_meeting), and also get the id each loop. I'm only getting the value 0 for each when I don't overlap the object (that part's correct), and 1 for each variable when I do. What am I doing wrong here? I should get an instance id value (a long number), and more than 1 when I overlap multiple instances of Tree_obj, but all values are 1 right now.

Script:

obj_id=0
obj_collision_count=0

//check repeatedly for all obj2s at are at these coordinates

with
(
object_index==Tree_obj and place_meeting(x,y,Tree_obj)
)

{
//set obj_id to colliding instance add obj_col_count if collision

other.tube_id=place_meeting(x,y,Tree_obj)

if other.obj_id!=0
{
other.obj_col_count+=1
}
}
//repeats process until number of collisions with Tree_obj is found
 

FrostyCat

Redemption Seeker
First of all, that is no way to use a with block. object_index == Tree_obj && place_meeting(x,y,Tree_obj) is not a valid object ID, instance ID nor one of the special values compatible with it. Read the Manual and stop making up syntax.

Also, this whole time you kept trying to set tube_id while leaving obj_id unattended at 0, and ditto with obj_col_count and obj_collision_count. Hence the behaviour you observed.

The next time you get tempted again to use a Boolean expression in that position for a with block, stop the nonsense. Think how it can be transformed into a with-if filter block from the perspective of the instances being looped over. Then put that down instead.
Code:
obj_id = 0;
obj_collision_count = 0;
with (Tree_obj) {
  if (place_meeting(x, y, other)) {
    other.obj_id = id;
    other.obj_collision_count += 1;
  }
}
 
Yeah I'm not that used to how the with construction works yet. I meant to rename all entries of tube_id into obj_id, but I missed that one. I was trying be clearer here about what it holds.
 
Top