Hello everyone,
I create an option menu with 3 HSliders to define speed and sentivity of mouse.
I would like to store value before launch a level, i try this :
extends Spatial
onready var GreyScale = get_node("./Control/GreyScale")
onready var niveau1 = get_node("./Control/VBoxContainer/niveau1")
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
set_process_input(true)
pass
func _unhandled_input(event):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_ESCAPE:
get_tree().quit()
func _on_niveau1_pressed():
var HS1 = get_node("./Control/GreyScale/HSlider").get("value")
var HS2 = get_node("./Control/GreyScale/HSlider2").get("value")
var HS3 = get_node("./Control/GreyScale/HSlider3").get("value")
script_save_load.save_game({"MAX_SPEED":HS1, "JUMP_SPEED":HS2, "MOUSE_SENSITIVITY":HS3})
get_tree().change_scene("res://_Scene/Scene2.tscn")
pass # replace with function body
func _on_Options_pressed():
if GreyScale.is_visible():
GreyScale.hide()
niveau1.show()
else:
niveau1.hide()
GreyScale.show()
pass
I created so an script to save and load value :
extends Node
var ContaSet = 0
var savegame = File.new()
var path = "user://savegame.save"
var Dict = {
MAX_SPEED = 10,
JUMP_SPEED = 10,
MOUSE_SENSITIVITY = 0.02
}
func save_game(Dictnew):
savegame.open(path, File.READ)
savegame.store_line(to_json(Dictnew))
savegame.close()
func load_game(name):
if savegame.file_exists(path):
savegame.open(path, File.READ)
Dict = parse_json(savegame.get_line())
savegame.close()
else:
savegame.open(path, File.WRITE)
savegame.store_line(to_json(Dict))
savegame.close()
return Dict[name]
And when I launch a scene i try to do this :
var MAX_SPEED = script_save_load.load_game("MAX_SPEED")
var JUMP_SPEED = script_save_load.load_game("JUMP_SPEED")
var MOUSE_SENSITIVITY = script_save_load.load_game("MOUSE_SENSITIVITY")
But I don't know why my velue it isn't store and load in scene in game.
And I would like when i launch game that Value of HSlider is define by the File savegame.
I need help...