0 votes

Sorry for my English, I'm using the google translator.

Hi, I'm doing a platform game, which consists of 20 levels.
The logic to be able to go to the next level must collect 3 points (at the moment I call them "stars") so pass the level, but I have not found a way to implement this, I obtained a couple of Scrips online.
These implement directories and their use but I still do not understand how to apply it for this specific case. What I understand that the directories would do in this case is to save the status of the levels, that is, which levels are locked and which are not.

Can you advise me with this?

Script Button to select level

extends Node2D

export (int) var level
export (String) var leveltoload
export (bool) var enabled
export (bool) var scoregoalmet

export (Texture) var blocktext
export (Texture) var opentext
export (Texture) var goalmet
export (Texture) var goalnotmet
onready var levellabel = $TextureButton/Label
onready var button = $TextureButton
onready var start = $Sprites
func ready():
if gamedata.levelinfo.has(level):
enabled = gamedata.levelinfo[level]["unlocked"]
enabled = false
func setup():
levellabel.text = String(level)
if enabled:
button.texturenormal = opentext
button.texturenormal = blocktext
if scoregoalmet:
start.texture = goalmet
start.texture = goalnotmet
func onTextureButtonpressed():
if enabled:

This script is the autoload that checks the status of the levels. As I said I saw it online in a CandyCrush style game.
That is why it says "goal" or "Score Goal" which I understand I must use to be the one to check the status of the "stars", if all 3 have already been collected


extends Node

var levelinfo = {}
var defaultlevelinfo = {
"unlocked": true,
"starsunlocked": 0
onready var path = "user://save.dat"

func ready():
levelinfo = load_data()

func savedata():
var file = File.new()
var err = file.open(path, File.WRITE)
if err !=OK:
print ("Algo esta mal")

func loaddata():
var file = File.new()
var err = file.open(path, File.READ)
if err !=OK:
return defaultlevelinfo
print("Algo esta mal")
var read = {}
read = file.getvar()
return read

link image: https://imagizer.imageshack.com/img923/2799/q31zL4.png

The gray star that is observed under the button is the one that indicates in the menu of levels if the 3 "stars" were already collected changing to a golden star in this one.

in Engine by (16 points)
edited by

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.