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
Nivel

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

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"]
else:
enabled = false
setup()
music.stop()
func setup():
levellabel.text = String(level)
if enabled:
button.texturenormal = opentext
else:
button.texturenormal = blocktext
levellabel.hide()
if scoregoalmet:
start.texture = goalmet
levellabel.show()
else:
start.texture = goalnotmet
func onTextureButtonpressed():
if enabled:
gettree().changescene(levelto
load)

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

GAMEDATA GLOBAL VAR AUTOLOAD

extends Node

var levelinfo = {}
var defaultlevelinfo = {
1:{
"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")
return
file.storevar(level_info)
file.close()

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 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.