Event condition acting as a value attribution instead of value checking

Hi. I think I’ve found a bug in event condition.
Context:
I’m making a board game. Four players have four pieces each. One player is human controlled and the others are computer controlled. To identify the pieces I’m using an object variable called Id. To better control this players pieces I’ve created an array which has some childs with boolean, string and numbers values. To cicle the pieces for the computer controlled players I’m using one of these number childs that I’ve called NextPiece. Here are a capture og this array seen through the debbuger:


There is a rule that in some conditions a piece cannot move so in this case the next free one must move.
It was in this situation that the things got weird. I’ve inserted an event with a condition to check if the Id of a piece is equal to the value of NextPiece. A screen capture of the event an its conditions follows:

The original condition is at the subevent and disabled so i could test the workarround. When this part of the code, with the original condition, was executed, a structure variable called Players was inserted into the Piece Object, with the structure of the NextPiece part of the global variable Players and with a zero value. I’ve used the expression condition of comparing two numbers as workarround and it works fine. As long as I understand the original condition and the new working one should be basically the same. There is no action of attribution of the value NextPiece to the object Piece in this event neither in any other event in the game’s “code”. There is, of course, the other way arround. I mean the value of the Id of the Piece is attributted to NextPiece.
Maybe I’m missing something, but I don’t thik so.

Your crossed out line appears to be missing the GlobalVariable( before Player …)

1 Like

Yeah, thats true, but even then a condition shouldn’t turn into an attribution.

I’m not really following what you’re meaning by “attribution”, and the screenshots don’t really show anything that I would consider that.

Keep in mind though, any time you check for a variable (whether via a condition, action, or expression) of any kind, if the variable doesn’t exist, it will be created with a default value (0 for value variables, “” for strings, etc). The system doesn’t allow null values to avoid crashes due to invalid calls.

1 Like

It seems that when you check if the ID equals the array without the GlobalVariable() it’s creating the array for the object. I know Gdevelop creates variables if they don’t exist but this doesn’t make sense. I don’t know why it creates it as an object variable. If GlobalVariable() is added, the variable isn’t created.

1 Like

Yes, but in this case, it’s creating it as an object variable. It has to be connected to not using the GlobalVariable() part but I don’t know why it creates it as an object variable.

image

This is my only event. It works as expected with the GlobalVariable() but creates an object variable without GlobalVariable(). Yes, the syntax is incorrect but it shouldn’t result in the creation of an object variable. It should do nothing without GlobalVariable(). I’m assuming without something to tell it what it is, it’s just using the current variable scope or whatever the proper term is.

1 Like

Both expressions should show an error because of a wrong type: number vs variable identifier.

With a scene variable, it won’t have any effect because the generated code doesn’t know the scene.

gdjs.VariablesContainer.badVariablesContainer.get("Foo").getChild(1).getChild("Bar")

For an object variable, it does something by chance because it uses the last object in the condition.

gdjs.Untitled_32sceneCode.GDNewSpriteObjects1[i].getVariables().get("Foo").getChild(1).getChild("Bar")

Thank you all for investigating on this. We will plan a fix for a future release.

3 Likes

I’ve fixed the condition correcting the error that Keith_1357 pointed and it worked fine. By the way, thanks Keith. Is good to have some one else looking at the code and spoting the error that I missed.
Silver-Streak is right in pointing that my captures doesn’t show the creation of the structure in the object. I’ve failed to provide that and now the code is right so I don’t have the situation to show. I might made an simple program to repeat the situation if its usefull.
I’m glad that my mistake may have showed some point of improvement. And I want to thank you all for the replies. It helped me to undertand better the behaviour of conditions regarding missing/mispelled variables.

2 Likes

It was a good catch on your end as well. They seem to be fixing it. I love that there’s actually people from Gdevelop in the forum and that they’re transparent about things. Too many help forums are just community driven. This is a nice mix of both.

I don’t like how lose Gdevelop is with variables. It will casually change a variables type and create variables if they don’t exist just by trying to read them.

I can appreciate that it’s doing it to prevent projects from crashing like would happen in other languages. I just wish that when an app is being created, Gdevelop was stricter and let you know when it was doing those things because yes it prevents the app from crashing but it can also cause weird behavior.

I wish the app had a mode where it would crash or pause when the debugger found an error so you knew exactly where the problem was. But… I also understand that they’re trying to balance things and keep it easy to learn and use for people new to the whole concept. You don’t want to discourage or frustrate new users and stopping at every error probably would be pretty frustrating to new users but it would create cleaner code.

Gdevelop is my current favorite app maker because of it’s simplicity. I honestly get confused by the apps that break everything up into separate files and require imports or references.

1 Like