[SOLVED] How can i set back the position of the player after switching and coming back i want my player when entering a shop or house and quit it to be near the door not in the original coordinates

hey i just woke up thank you for your replay, Man i was sleepy asf , i tried and it worked thank you so much im gonna just adjust a coupe of things, its been like a whole 3days and i was stuck on it u’re like a hero appreciating your help a lot and all the others. and if i found the solution for the other method im gonna post it here so if anyone needs it .

Hey erdo thank you for your help. im not trying to make the new undertale or hollow knight im now in the learning phase im just trying to work on new mechanics u know just to learn. im taking it slowly this one was hard so i came to ask for help im just a begginer you know. thank you for helping me out you too appreciate it <3

Hey so i just find a solution as i said i was sleepy i didnt pay goooood attention of what @ZeroX4 said so here is it :

i created a sceen variable to save the cords that i want the player position when return in o the main map where to be and used “the pause scene and start” behavior and it worked the bad thing here is for every time i should create a scene variable as here :

now it spawns the player near that checkpoints

![Capture d’écran 2023-09-13 030351|690x325]

the bad thing here is for every door u should create a check point or spawn point as in the photo above.

for the other scenes i checked if the player is on collision and set hes position and i used the “Stop Scene and go back to the previous one” behavior and it worked
!!! (“as u can see down here”):

i will search for an easy way to do it so thank you all for helping out thank you soooooooooooooooooooooooo much . man i love the GDevelop community you’re all better than unity’s community<3

ps:" i dont care if it was wrong but it still work and thats the matter as they say if the code works just leave it "

ps2: “i added the flip action just when he exist the store he face the other way”

Try global variables
They work between scenes

Tbh I don’t know what I should do or say it works and that’s the matter :sweat_smile::sweat_smile: thank you for your help though

1 Like

If i understand correctly you wanted to streamline teleporting process

So that when you touch doors outside it save your current position but sends you wherever you want
So that when you touch doors inside you go back to that position WITHOUT need to specify it in X and Y but just using position saved to variable

In this case global variables are well GLOBAL and work across whole project including all scenes
So it would always send you back in front of doors you entered with
I still can’t see any reason to go with changing scenes instead of just going for different position outside map
But it is your game you know what is best for you not me not anyone else
If it works like you said then this is all that matters

Tbh I didn’t think of using global variables I’m gonna try it. And I just wanted to do it in different scenes why IDK LOL. I’m now in the learning phase so any advice you say I’ma take it. Tbh your method is so easier and effective than mine and saves a looooot of time so if anyone who has my problem I will suggest 100%your method cuz it’s easy as I said and beginner friendly doesn’t require a lot of work and do the job

Anyway thank you so much @ZeroX4 for your help I really appreciate it you’re a savior man :heart:

You see cause you want to do what you are seeing
You do not consider doing something else that would look as what you are seing

This will be example and another tip that will most likely come in handy

Imagine like in mario game you have coins just floating in the air
For player to pick them up

Your initial idea is to delete coins on collision with player to make them disappear and add +1 to coin count for each coin collected

Now you created a problem
How to spawn them back in exact same places?
Well doable but complex work and will need a lot of setting up in events to make it flawless

Now you go this way because it is what you see so you assume you need to delete these coins

And how about you do not delete them?
You change their opacity to 0 when in collision with player and only add +1 to coin counter for coins that opacity is 255 (255 is max opacity)?

Coins are still there you did not delete anything so you do not need to respawn them
You only need to set all coins back to opacity 255
While for you or any player it will still look like coins were deleted
You faked deletion effect yet you made your life easier

DO NOT ever try to do stuff as you see it if it is problematic
Try to think how you can fake effect doing something else

Same thing is with raycasting
Ppl often want to use rayasting to so enemy can spot you
Kinda like imagine having flashlight light if player is inside that light enemy see you
1st thing you and others will think is best is to raycast from enemy and if it hits player then you are spotted and enemy goes into attack mode and chase you
(BTW raycast is nothing else than creating invisible line from object and checking if it collides with another object on its path)

And that is a solution but imagine you have 100 enemies on map and every single one of them raycast
Look how your FPS goes down (just kidding won’t be so bad but it eat up performance)

How about you raycast ONLY from player and check if it collides with enemy object?
For game it does not matter who is raycasting as long there is connection between objects
So instead of having multiple objects raycasting you now have only ONE
And it still works exact the same way and do exact same thing

Farming game
You want to use shovel to dig holes for plots and so when you do so you see dirt
1st idea make whole ground each grid a plot
I ask why?
How about when you have shovel in your hands press interact button to dig a hole to turn grass into dirt
Maybe just do not have grid made of grass plots
How about you just spawn object called dirt hole on top of grass?
This way instead of having whole map covered in grid of objects and switching these objects to different ones or simply switching their animation
You create that object when you need it to be there
While not pre creating tons of objects you do not even need

Think outside of the box

tbh thats genius for your method i see its the best way for a beginner to use like me.
the method that im trying to use is a bit advanced and challenging. your method was in my mind and a lot of games are using it like undertale and a lot of top down / platformer games. im just messing around here trying to create diffrent game mehcanics just to learn i said couple of times That im in the learning phase i still have a lot of things to do and to learn thank tou for your help till next time :heart: :heart:

1 Like

Hey im running into a new problem lol.
i created a Player Health System In The main Scene everything is okay the damage and the healing is good but when i go to the other scenes it dont load The player Main Scene Health I was Thinking of using Global Variables for It but Idk How To do It How Can i Do it ?

like idk how can i set those variables to global ones

You simply change them to global

There global variable conditions and actions
So i do not understand what you are struggling with?

when i set it into global variables theres something that i cant see the player is getting damaged but the health curser dont go down like this

Here is the events that i used :

Hey i used ur advice and im using the easy thing
im using now the health extension but still the same prob

i dont know how to save the players health after getting hit and switched scene

You switched to global variables yet you left expression object variables
So what did you expect?

Variable called Health
Would look like
As object variable Object.Variable(Health)
As scene variable Variable(Health)
As global variable GlobalVariable(Health)

So in your last event not

And in change width of health
Not Player.Variable(MaxHealth)*Player.Variabiel(Health)

you’re talking about the last one that i send right ?

I am talking aboiyt this one

A hey Thank you for saving my As* Again idk why i dont notice the simple details thank you again the first method worked and im just gonna ask if you want about the second method how can i make it work i tried switching everything to Global Objects but it still dont work anyway thank you for helping again i do really appreciate it
last thing im gonna ask is how can i delete this object when its on collision with the player i used the delete object beahvior but when exiting and comeback after it just appeared again.

for anyone that want it:

2nd method of what? i do not understand?

Also switching what to global object?
Or you mean variables to global variables?

So as I said I used the health extension as a 2nd method

The problem that I tried switching everything to global variables but still when switching scenes the health go back to normal