0
votes

I try to make a game in wich the player makes atoms. I'm really far in making a good looking and working game.

But now I want to make the atoms have different properties for different phases (solid, liquid, gas) I found that I can't use Phy_restitution because it doesn't exist, so I tried making three objects (solid, liquid and gas) and give them their own properties.

But this didn't work. The create event checks in wich state the atom should be and creates that state, but this gives me a error.

How can I make three phases with different restitution of this atom?

------create event------ obj_h_parent
temp = global.temp
if temp < 14 instance_create(x,y,obj_h_solid) instance_destroy()
if temp > 14 and temp < 20 instance_create(x,y,obj_h_liquid) instance_destroy()
if temp > 20 instance_create(x,y,obj_h_gas) instance_destroy()

the error that I got was :

FATAL ERROR in action number 1 of Create Event for object obj_h_parent:

PerformEvent recursion depth failure - check for infinite loops, check objects for parenting at gml_Object_obj_h_parent_CreateEvent_1 (line 4) - if temp > 20 instance_create(x,y,obj_h_gas) instance_destroy()

I today tried to do it another way by making three objects and letting them check the temperature when they are created by: temp = global.temp if temp < 14 instance_create(x,y,obj_h_s) instance_destroy() if temp > 14 and temp < 20 instance_create(x,y,obj_h_l) instance_destroy() if temp > 20 instance_create(x,y,obj_h_g) instance_destroy()

But when I runned it game maker gave the same error as before. And I have deleted the parent.

1
What's the error you're getting? - GAntoine

1 Answers

0
votes

Looking at your error message, I assume obj_parent is the parent of your liquid, solid and gas objects. I also assume that in the create event of the children, you use the event_inherited() function, or that you left this event blank, leading to the same result.

So when you create your obj_parent, the create event immediately creates a children, that runs the same creation code, meaning that it also creates an other instance before destroying himself. Then this new instance creates an other, that creates an other, that creates an other, etc. This is where your infinite loop is.

Before creating & destroying, you should first check if your instance isn't already in the correct state. Or you could use the instance_change() function and tell it not to run the creation code again. https://docs.yoyogames.com/source/dadiospice/002_reference/objects%20and%20instances/instances/instance%20functions/instance_change.html

For example :

temp = global.temp
if (temp < 14) instance_change(obj_h_solid, false);
else if (temp > 14 && temp < 20) instance_change(obj_h_liquid, false);
else if (temp > 20) instance_change(obj_h_gas, false);