Object random point(x) position at creation

I must be doing something wrong that I don’t understand. It’s very simple, I create a “kanjiTree” sprite, I create another “kanji64” sprite. I move “kanjiTree” to a random position of X(). Then I tell “kanji64” to follow his position.

If I separate these two actions, pressing one key at a time, it works perfectly. The two sprites are created and when I press the key they align.

If I put the two codes together, it doesn’t work, every time I press the “kanji64” key it has a totally random X().

What am I missing?

HI, I am no expert but what if you create sub-event for the Kanji64 movement. with no condition

I just tested it, but it doesn’t seem to work. Kanji64 appears in a random X() every time I press the key, instead of aligning.

It only works if I separate it into two different keys or put the align event that each frame is always being checked, which seems absurd to me in this case, because the sprites once created will not move.

Because I’m going crazy, I’ve created a clean and empty project, I’ve created only two sprites and this code that does the same.

It doesn’t work either, every time you press K, “fruit” appears in a random X place.

I have put logs and it tells me the same number every time, but it is totally false because in the preview of the game they come out in different places.

It’s like generating a random value for “tree”, using the same for “fruit” and right after moving “tree” to another place for some reason that I don’t know. Is it a bug?

Update: If I generate the random number before, and everything else remains the same, it works perfectly. I dont get it.

What happens if you “create object kanjiTree at position Random(100, 400); 100”, and “create object kanji64 at position kanjiTree.PointX("kanjiAttach");kanjiTree.PointY("kanjiAttach")”?


Whether that fails or not, I suggest you raise it as a bug. It should work like you had originally.

Same result, this was my first attempt, and because failed I separated it to see if that was the mistake.

Ok, raise it as a potential GDevelop bug.

1 Like

And if you précise 'Execute only one time" in the first condition

Why? The “key is released” condition only happens once. Adding a “Trigger once while true” is completely pointless.

Also tested, same result