Variables (global and scene)

I have some problems with variables in my game. I have my rooms based on ID, and each room ID has a global variable that is changed as it moves from room to room. It works perfectly, but I found a bug that I can’t fix.

For example:

Note that the text shows the current room the character is in, which in this case is ID 1.

When moving to another room, he must change the ID to number 2, this is what happens in the image below:

But notice a problem, the ID only changes if my character is all inside the room. If I go back a little, the ID changes to the previous room:

However, this does not happen if I leave this variable as, scene variable, see the difference:

With the scene variable, I don’t even have to show up with all my character that the room ID already changes, the same goes for all other rooms.

I believe this is a bug, because it makes no sense to use the same procedure for both and the result is different



The fact that I need to use the global variable is that I have other scenes that will need the ID’s for each room. That’s why I can’t use the scene variable, at least for that.

Because the global variable recognize the collision in all scenes (1 and 2) while the scene variable recognize only the collision in the scene 2.
Try to use a inverted condition: if player is colliding with obj_camera id=1

This is a problem, I’m not using multiple scenes, it’s just one with the camera’s limits.
Each obj_camera a room with its proper ID.

Other scenes I will use for other procedures in the game, such as load, save, teleport etc … That’s why the use of the global variable.

See my example 1: Here I create enemies as soon as I enter the room, but as the ID does not change instantly when moving to another room, the enemy will only be created after the ID changes.

Example 2, works perfectly in the room, but when creating the enemies, they disappear immediately after entering the room, the vision of them disappearing is clear.

Your player is colliding with 2 obj_camera at same time. That’s causing the error.
Why don’t you use distance instead of variables?
If player.X()> whatever = Actions.

I would just like to understand why a global variable that receives the same value, manages to have a different result than a scene variable. I don’t understand the logic behind it!

I tried to create another scene variable, so that it receives the contents of the global variable, and the delay occurs the same. In other words, it went through the global variable, it breaks the logic - at least mine -

I just want to create enemies according to the room visited, without delay, and delete enemies from the rooms that the character is not in.

As I said, in example 1 that I posted it works perfectly, but it has the damn delay when entering the room, since with the scene variable, it does not have any delay, but the enemies are stopped after the first room …

What’s your “obj_camera”?
The player will be always colliding with it?
It’s invisible? Did you put 1 for each “visao”?
I don’t get your code!

It works as follows.
my obj_camera is the background, and each obj_camera animation has a room that will be visited by the player. See the image below:

Obj_camera, has a variable ID number, which receives the number of the animation for the room in which the player is.

So, I created a global variable, called “g_game_id”, which is part of my map, which shows the room the player is in. It receives the ID of the current room, and with this variable, I do “n” functions, which work perfectly.

As I decided to dynamically create enemies around the room, I check if the variables in question are identical, that is, if the current room is the same as in the obj_camera and if they are not, it does not create enemies. OK perfect! It works without any apparent problem.

In the search for bugs and everything, I found this problem of the topic.

As for “visão” it is only to create a hitbox of the enemy’s attack

OK! got it.
I tried to replicate it, but I didn’t know how you were changing your global variable.
If you can upload your game I can check for you.

Oh sorry. But I can’t, in addition to having several paid files, the game is already over 500MB. Don’t be offended, friend.

I know you just want to help. If there is another way, thank you!

Sem problema! Entendo!

Hmmm…it looks like you’re using a concept similar to my metroidvania camera example (GDevelop Metroidvania Camera Example by Silver-Streak), then trying to use the “Camera Rooms” as a way to trigger other events, is that accurate?

Because your object can be in collision with two places at once, you’re likely going to need to set up some events to differentiate “Current room” vs “Old Room” to ensure it only triggers once you’re fully in the next room.

I do something like this for “room transitions” so that it fades out while leaving one room and fades back in.

In general, I’d say try to have your conditions for “obj_player_camera” is in collision with “obj_camera” ALSO include “Number of “obj_camera” = 1”. This way it only activates when you’re only in collision with one room (obj_camera). You might need to tweak the rest of your events to use this similar logic.

I found the problem, just something I didn’t know and at least I never saw anyone comment.
Whenever I use a Variable other than the one in the scene, I must use for each, and in this case, the error was on my camera

I was not using for each. In this case I noticed that some variables that I used with the camera were from the scene, and worked well, while others that were global, were not. I solved the problem just by changing it. Simple thing, but it took me a whole day to solve.