0 votes

Hello! My 2d platformer game is structured like this:

- tilemap
- player
- enemys

The problem is that the player’s script needs to access the tilemap and other nodes.

If I do get_node(‘/root/level03/tilemap’) it works but then the next level04 won’t work.

If I do getparent().getchild(0) it also works but then I have to remember to keep the same structure all across the levels.

I thought in something like store a variable CURRENTLEVEL=00 and increase it and then just getnode(levelCURRENTLEVEL /tilemap) would be perfect but I can’t make it work
Is there any other way to do it?

Thank you!

in Engine by (58 points)

just my idea not sure work or not but

var map_lvl = 1
var node ="level" + map_lvl


2 Answers

0 votes
Best answer

get_tree().root.find_node() i think.

by (220 points)
selected by
0 votes

Definitely you can use variables. Like CURRENTLEVEL you used.
There are many ways to do this, it's about how you construct the program.
An example way to control different levels: Before you start the game, assign which level will lead to which level by using a variable. For example, in level1, you use lead_to_level = LEVEL_2 where LEVEL2 is a level scene.
You can also keep all the level scenes into an array if you want.
There are many different ways.

by (765 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.