[SOLVED] How can I create something like "procedures"?

Hi guys, newbie here :smiley: !

This is my first game, “Omega Clash” (goo.gl/YuN7bH).

So, I’m doing OK with GDevelop, but I have a little problem…

How can I do something like “functions” or “procedures” to avoid code redundance?

Explaining: on my game, the player can be destroyed when hit by a:

  1. collision with a meteor
  2. collision with an enemy
  3. collision with an enemy shoot

So, in this three cases, I am setting up redundant “code” to:

  1. Flash the screen red
  2. Verify if the variable LIFE is bigger than 0
  3. Play an explosion sound

Can I do something like a function to avoid this annoying repetition :confused: ?

There are no functions for HTML5 (the extension is available in the native platform), but it’s in the roadmap: Support for HTML5 functions in the roadmap

Maybe you can achieve your logic with a big “OR” advanced condition:

Conditions: OR (if true any of) Player collides with Meteor Player collides with Enemy Player collides with EnemyShot Actions: Red screen (sub-event) Check if variable life is > 0 Play sound "explosion.wav"

Personnaly, i use an external events to manage a “super class” for my canons (about … 6000 events/actions ?), everything is based on external xml files, values parsing (while loops), and something looking a relational database with unique ID and concatenations. It’s harsh, took me a lot of time, but it works like a group of multiple cascading procedures.

Oh yeah, external events are a good choice too, I suggested it because the problem is simple :slight_smile:

:open_mouth:

Thank you a lot! It worked like a charm on my prototype.

Well, I have now a little problem : I’m using the “OR” to group the collision between the Hero shoots and the enemies. It worked fast and well, but now I am having trouble (sorry guys, using GDevelop for a few days and still a real noob :blush: ) with a little special effect: the X and Y coordinates of every enemy explosion animation sprite.

I’m trying to do something like this:

Conditions: OR (if true any of)
                Hero_Shoot collides with Asteroid
                Hero_Shoot collides with Enemy01
                Hero_Shoot collides with Enemy02
Actions:
         Delete Asteroid
         Delete Enemy01
         Delete Enemy02
         Create Enemy_Explosion on the dead enemy X/Y coordinates < Don't know how to do this
         Play sound "enemy_boom.wav"
         SCORE += 50;        

:blush: Well, I did a workaround here… I added an animation 2 to every object displaying the explosion…

When hit, the object changed to the animation 2, and is deleted after the animation stops.

EDIT: I was so happy with my workaround, so I realized that:

  1. The game is running OK on Firefox, with the explosion animations playing the way I want
  2. The game runs on Chrome, but when I change the animation to (1), the enemy vanishes!

So… let’s read the documentation.

In the future you’ll want to use “Object Groups”, if you create the group “PlayerHit” with the objects “Asteroid”, “Enemy” and “EnemyShot”, you can easily check the collision with this group:

Conditions: Player collides with PlayerHit Actions: Create explosion, etc. Delete PlayerHit
If the explosion is different for each object (actually, an asteroid doesn’t “explodes”), you could create an object variable inside each object storing the animation for their explosion, for example the asteroids have the variable “Explosion = 1”. Finally, change the explosion animation to “PlayerHit.Variable(Explosion)” before delete the PlayerHit object :slight_smile:

The image used for this animation has a different format?
Do you change the Z-order of the explosion after creating it so it’s rendered over the background and other objects?

Hello, good friends!

I am enjoying GDevelop a lot :smiley: !

Man, this is way to easy :mrgreen: ! Thank you, Lizard-13!

No, the imagem is a png file, and I didn’t mess with the Z-order. To be true, I’ve found myself in a very strange situation:

  1. When I open the index.html locally with Firefox, the code runs OK;
  2. When I open the index.html locally with Chrome, the explosion animation will not work!

I uploaded my new code to Gamejolt, and when I load the game at Chrome, explosions didn’t work.

BUT… I uploaded the same code to itch.io, and EVERY feature is running fine at Google Chrome!

The itch.io address is: rohling.itch.io/omegaclash