Inserting "IF" in IDE without javascript, is it possible?

HI! I have some doubts and, i believe that these procedures can be done by javascript, but the fact is that there should be an example of how to work with objects from the command line. At least the basics. But it would be interesting to implement in the IDE itself without needing command lines.

Would it be possible to implement an “if” to know what kind of object we are moving?
Example:
if “object”= “enemy_giant” then

else

Sometimes it’s necessary to distinguish what kind of object we’re programming, because when using by group, we always have to put only what the IDE gives us.

Also, would it be possible to implement an “if” to check if the animation is correct?
Example:
if animation = “cast” then

else

It’s just a feature I wanted to see. And if there is already, please disregard it, and if possible, post here how to do it.

These days I wanted to be able to distinguish what kind of enemy appeared in a given location, in case there was any pattern corresponding to what the player did. I don’t remember for sure, but it was something that would be created if the player had different choices and paths. Anyway, I had to forget about it for now and continue my game.

Events are already if statements, and already select the right objects. For example, this:


Is equivalent to

if(isBeginningOfTheScene()) {
    var scroll_speed = 1;
}

Or if you use an object condition (a conition that accepts an object as parameter) it will be called for each instance of the object and the actions called on the objects where it is true (it is called object selection). For example this:


Is equivalent to this:

const selectedInstances = [];
for (const instance of allInstances) {
  if(selectedInstances.variable.a === 1) {
    selectedInstances.push(instance);
  }
}
for (const instance of selectedInstances) {
  instance.hide();
}
3 Likes

So I’m not sure what the actual request is.

There isn’t a “command line” within GDevelop. For clarity, all events are If statements. The condition box is your If qualifier. What you’re asking for exists (mostly) in the engine.

So for “if animation = cast”

Is done via “The animation of Object is “cast”” condition
image

You cannot detect the type of object currently via events or expressions, but your example isn’t asking for that. You’re asking for the object name of an object in your example (If ‘object = enemy_giant’), that can be done via the “Compare two strings” condition by using the Object.ObjectName() expression (available via the expression builder). It’d look like this.
image

Else doesn’t exist in the logic of the engine at all, and mostly isn’t needed, you can just add the same conditions again and right-click them to select “Invert”, which will basically operate as an “whenever these conditions ARE NOT met” (which is the same as an else 99% of the time).

2 Likes

How can I make the code below in GD?

if group_enemy has “cast” animation then
animation = “cast”
else
animation = “idle”

Unfortunately, you cannot test for the existance of an application by name, you can only test what the current animation name is.

2 Likes

a stupid workaround:

command 1
animation = “idle”

command 2
animation = “cast”

If cast exist, the animation is cast, if not the animation is idel

1 Like