Hi everyone, I’m struggling with a 2D fire-extinguishing system in GDevelop, and I need some guidance. I have multiple Fire_Core objects, each with an object variable Intensity and IsActive, and I’m trying to implement different fire classes that respond to specific extinguishers.
The problems I’m encountering are:
When I spray a fire, all Fire_Core instances are affected at the same time, even though I’m using “For Each Fire_Core” and the object variables are meant to be shared across all instances.
I’ve tried switching to instance variables, but GDevelop doesn’t let me set unique values for all instances via the events sheet without creating them manually one by one.
I need the logic to only reduce the Intensity of the fire being hit, respecting its fire class and compatible extinguishers.
I’m currently using:
“For Each Fire_Core” events
Collision conditions with the player’s spray
Object variables for Intensity, IsActive, and FireClass
OR/AND conditions for extinguisher compatibility
Even after setting up everything in a “For Each Fire_Core” loop, the problem persists: one fire core affects all, and the fire class logic doesn’t work as expected.
Has anyone run into a similar issue? Is there a correct way to make For Each truly work on individual fires while still using object variables? Any advice, examples, or workarounds would be greatly appreciated.
Right now your code reads:
Each instance of Fire_Core, that collides with SprayHitbox and IsActive=1 and FireClass=0 will reduce Intensity by 60 each second, as long as any Player with CurrentExtingusherIndex=0, 1, or 2 exists in the scene.
I can only guess, that you want FireClass to be matched by CurrentExtinguisherIndex. Is that right? In that case you need to compare those two variables. E.g.: FireClass of Fire_Core = CurrentExtinguisherIndex
You also won’t need “Repeat for Each”.
Regarding unique instance variables: As far as I am aware, you can only assign them in three ways:
In the Scene Editor via Object Properties
After creation via the Create Object action
By cycling through each instance (For Each Event) and assigning your variables individually/collectively
Also, you don’t need the AND-condition here. An event block will always check all conditions, unless stated otherwise.
Yes the FireClass should match the CurrentExtinguisherIndex
It follows these fire classes
FireClass 0 - 4 = A, B, C, D, K
Respectively,
The CurrentExtinguisherIndex follows this
FireClass A = Water (0), Foam (1), Dry Powder (2)
FireClass B = Foam (1), Dry Powder (2), CO2 (3)
FireClass C = Dry Powder (2), CO2 (3)
FireClass D = Dry Powder (2)
FireClass K = Wet Chemical (4)
Ah, I see. There is many ways to do this. Three lines can be sufficient here.
You could, for example, change your FireClass to a TextVariable and fill it with “012”, “123”, “23”, “2”, and “4” respectively (for your respective classes A,B,C,D,K)
Then simply use the condition: FireClass of Fire_Core contains Player.CurrentExtingusherIndex
That way only Fire_Cores will be picked, which contain the IndexNumber of the Extinguisher the Player uses. This also works with words. So you could also set the Text Variable to something like “Water, Foam, Dry Powder” and change your Extinguisher Variable to a text variable as well. That makes it easier to read as a human.
Then you only need to check the IsActive Variable and do the collision check (collision last, due to performance), and get rid of “For Each”, "AND, or “OR”.
Other people may recommend using Arrays or Structures, which would be useful if you had a lot of different combinations to check, or bitmasking, if you want to geek around.
Good luck for your project and don’t hesitate to ask again.
I don’t know what the numbers represent but you could check if the current extinguisher type contains the type of the fire. Some extinguishers work for say “abc” so you could check if the extinguisher type variable say “abc” contains the fire type say “a” (does “abc” contain “a” using the variable names while paying attention to the case meaning all in lower or upper.)
Gotcha. A structure might also help convert from say water to the type of fires it fights. Or maybe a collection of booleans for each type. So many options.
The incorrect extinguisher can also cause the fire to accelerate and spread like putting water on an oil fire.
Good news. The fire class system is now working properly. I switched from number variables to text variables using readable words instead of indexes, and that made the logic much clearer for both me and my classmates. The “contains” condition suggestion worked really well.
I also realized I forgot to mention earlier that each Fire_Core already had its own FireEmitter from the beginning. The emitters were not shared between fires.
However, the issue where fire cores still get affected one by one has not fully gone away. Because this is a deadline-based school project, I have decided to move forward with separate fire objects for now instead of continuing to debug the single-object setup.
My plan is:
Fire_Core_1 with FireEmitter_1
Fire_Core_2 with FireEmitter_2
and so on
Each fire core will have its own corresponding emitter with matching numbering. That way I can guarantee each fire operates independently without unexpected cross-effects. It may take more setup time, but it allows me to continue development instead of getting stuck.
Thank you again for all the suggestions, especially the text variable approach. It really helped improve the clarity of the system.
Good to hear. Just go with what works for you. Whenever you want something to apply for multiple objects you could create object groups for that purpose.
And just in case you are interested: there are object linking conditions and actions, that link your specified instances of different objects with each other. Here you probably need the „For each“ event.