Refer to multiple group in a same event

Hello. I have this event that doesn’t work because all the objects in the “characters” group belong to the “object” group, too. How can I solve? If you want more information don’t hesitate to ask.

Try to add an id variable to identify your characters and your objects, then inside the foreach just add like
Foreach characters
if object.variable(ID) = character.variable(ID)
Do your stuff here…

Thank you but it didn’t work, maybe it’s better if I try to contextualize the matter better: I’d want that if at least one “object” object (character or not) respect the conditions, that are related to a “characters” object (the one of the foreach), it modify a variable of the same “characters” object.
I think the problem is that the conditions refer to two objects, but I don’t know how to solve this.

But I forgot to tell if you add variables you need to do two foreach to identify characters and objects

Like
→ ForEach characters
—> ForEach objects
------> if object.variable(ID) = character.variable(ID)
This way is picking a different pairs of object/character to test.

If this doesn’t work either just try to explain us exactly what is that you want to do and share some screenshots so we can help you better.

2 Likes

Unfortunately, that didn’t work either, so I’ll try to describe better what I want to do: I created a system that moves the characters to their “pos.X” and “pos.Y” variables in a 32x32 grid. The tiles and the characters are in the “object” group and the characters belong to the “characters” group. The event in question is designed to handle the collisions: if a object position is equal to a character’s “pos.X” and “pos.Y” and the “collisions” variable of the object is equal to the “facing” variable of the character, before the character move towards those variables the game should reset them to the position of the character to keep it from moving. Hope it helps, and sorry for my bad English.

Look what I do in that case is to use two additional object variables to store the X/Y of the object before collision and another pair of object variables to calculate the new X/Y of the character.
Looks like:

this way you can forget about calculations because you know the (saved) previous X/Y before collision and the target X/Y is (saved) calculated after or when is the collision.
Is hard for me to explain this my English is not good. Hope you understand the idea.

Do the target variables contain the position of the target or variables with values negative (-1), positive (1) and null (0)?

Sure you can store any number just make sure to set the object variable to be a number.
Look a sample I made just run and right click and you can see in debugger the targetX,targetY is updated

https://drive.google.com/file/d/1wFUkldUfv73tUKlMckkCPM5zzsXIiUji/view?usp=sharing



I think a way to distinguish two objects of the same group in a same event could solve my problem. For example, in a “compare two numbers” condition object.X() = object.X() I would want it to distinguish the two objects. Is that possible?

You can try but I think is the same as with ids if you assign every object an ID always are going to be different too
What I do is to set a scene or global variable player_counter = 0 or 1 depending on the game needs then when I create the player in the foreach increment the
Foreach or Repeat X times
Create player
player.variable id = player_counter
player_counter +=1
something like this


then when I need an ID or compare just do this

Look at this for each I compare the id of the player is equal to the ball and not equal to some global variable
And you can see here each player has its own ID

Ok, I solved my problem creating some scene variables to store the object variables; it could be a raw solution, but I think that it is okay.

I’m glad you solved.

I believe the only way is to use a custom behavior.