Ask here your questions to get help using GDevelop.
User avatar
By khaledali
#68039 I have a ball but i have copies of it (could be 5 or less)
when this ball is in collision with "something" i need to get this specific ball to re spawn to it's original location i started the level in .

The problem is ... i can't put the ball i'm holding in it's original position when it's in collision with "something" because well .. it's just the same object so all copies of ball "including original ball" go to the same re spawn location .
so only what i can do is re spawn all balls "copy or not" in the same location ..

The question is ....
I have a ball in location A ... i have the same ball but a copy in location B
how to get ball in location A to re spawn in location A when in collision with "something"
and the same for B ..
how to get ball "copy" in location B to re spawn in location B when in collision with "something"

Is this even possible or do i have to go with the easy option which is just make separate objects called ball A .. ball B .. which will be just a nightmare to do ?

Thanks for helping as always ...
User avatar
By Lizard-13
#68041 Just use object variables, save the initial position of each ball in the ball itself:
Code: Select allConditions: At the beginning of the scene
Actions: Do = Ball.X() to the variable StartX of Ball
         Do = Ball.Y() to the variable StartY of Ball

Then at collision make the ball go back to its saved position:
Code: Select allConditions: Ball collides with "something"
Actions: Do = Ball.Variable(StartX) ; Ball.Variable(StartY) to the position of Ball


If something works weird maybe you have to use a for-each Ball loop in one of the events ;)
EDIT: No, just tested, you don't need for-each loops at all :)
User avatar
By khaledali
#68042 Yup it worked really nice .. OK so can i give each ball a task .. for example .. if i touch ball A .. lets say a door gets created .. when i touch ball B the door gets deleted .. and they are of course the same object . is that possible ?

Thanks a lot for the help ...
User avatar
By Lizard-13
#68052 Yes, it's possible, you have to add a variable to each ball, for example add a variable"action" to ball A so "action" = "create door" and to ball B add the same variable but "action" = "delete door"
Then you can filter the action:
Code: Select allConditions: Mouse button pressed
            Cursor is over Ball
            Trigger once
Actions: No actions

        // Sub-event
        Conditions: Text of variable "action" of Ball is = "create door"
        Actions: Create object Door at X ; Y

        // Sub-event
        Conditions: Text of variable "action" of Ball is = "delete door"
        Actions: Delete object Door
User avatar
By khaledali
#68058 You just helped me a great help .. this will reduce a lot the time to work on the game .. i didn't even know that all of this exist .. i guess it's part of learning .. Really thank you a lot .
Now i only need to work on level design .. and other fun stuff .. and just finish the game .

Hope you like it when it's released :)

Have a nice day :)