CryAlone

  • Jun 15, 2020
  • Joined May 23, 2020
  • 0 best answers
  • @TwistedTwigleg said: Does the error display which line the Resource file not found: res:// is on or being triggered by?

    My guess would be the change_scene function call on `` is causing the issue. Maybe add print(scene) after line 12 in the first code snippet and see what it shows? Maybe it is not loading it currently. I might also suggest adding print(scene) between lines 2 and 3 in the second code snippet, just to make sure everything is as expected.

    Also, what is stored in scene when you save it to a file? The change_scene function takes a string that is the path to the scene file you want to load. If you pass a non-string to it, that could also be contributing to the issue.

    (Small note: I fixed code format. You can just post the code with a single tab indent or surround it with three ~ on either side)

    The error is on the continue button at "get_tree().change_scene(scene)", ive been trying to print the scene to see if is all alright but it says null over and over

    edit: nvm i got it working, i put "scene = get_tree().current_scene.filename" in the level transition scene and it worked : ) thanks

  • I have this code

    func save_data():
    	var file = File.new()
    	file.open("user://save", file.WRITE_READ)
    	file.store_var(scene)
    	file.close()
    
    func load_data():
    	var file = File.new()
    	if not file.file_exists("user://save"):
    		return false
    	file.open("user://save", file.READ)
    	scene = file.get_var()
    	file.close()
    	return true

    when i hit continue

    func _on_Continue_pressed():
    	load_data()
    	get_tree().change_scene(scene) 

    it gives me this... Resource file not found: res://, why is that?

  • @Megalomaniak said: Sounds like you haven't added some node or script relating to admob to your projects autoload. But that's just me guessing, I've never used admob.

    From my understanding, the engine doesn't have the singleton AdMob and i don't know why, i followed every step i dunno why its not working. Any suggestions?

  • I followed the tutorial from Shin-Nil from gifthub, but it says "Admob Java Singleton not found", i've check everything the sdk, adb, jaesigner, everything seems to be working (btw i can export the apk, i mean it works), what did i do wrong??

  • @TwistedTwigleg said: I have not tried saving the level I am in dynamically before, but it should be possible. If you have not seen it already, I would recommend checking the Saving Games page on the Godot documentation.

    To get resource path of the currently opened scene, which then you can use in a change_scene function call, you should be able to use the following:

    # assuming you are storing this in a dictionary
    "current_scene" : get_tree().current_scene.filename

    Then when loading, you can use the following:

    # We'll assume the loaded dictionary is a variable called loaded_data
    var saved_scene_file = loaded_data["current_scene"]
    get_tree.change_scene(saved_scene_file)

    And that should change the scene to whatever scene was loaded.

    One thing to note is that loading the scene will not keep the entities (like the player) in the same position they were in when saving. It will just load the scene like normal, as if you entered it for the first time. You may need to perform additional steps depending on how you want to handle loading back into the game.

    Also, I moved this topic from the tutorials category to the programming category, since it is a programming question.

    Is there a better way to make checkpoints and respawning the player where he left off? How would you do it?

  • I have a continue button in the menu how do i tell Godot that i want to load the "parent" from the json file or how do i save the level that im on ?

    in the player node i have this:

    func save():
    	var save_dict = {
    		"filename" : get_filename(),
    		"parent" : get_parent().get_path(),
    		"pos_x" : position.x, 
    		"pos_y" : position.y,
    		"speed" : SPEED,
    		"direction_x" : motion.x,
    		"direction_y" : motion.y
    	}
    	return save_dict

    and in the global script(save system) i have this:

    func load_level():
    
    	var level = "parent"
    
    
    	var save_game = File.new()
    	if not save_game.file_exists("user://" + name + ".save"):
    		return 
    
    	var save_nodes = get_tree().get_nodes_in_group("save")
    	for i in save_nodes:
    		i.queue_free()
    
    	save_game.open("user://" + name + ".save", File.READ)
       
    	while not save_game.eof_reached():
    		var current_line = parse_json(save_game.get_line())
    		
    		if current_line == null:
    			continue
    		
    		var new_object = load(current_line["filename"]).instance()
    		get_node(current_line["parent"]).add_child(new_object)
    		new_object.position = Vector2(current_line["pos_x"], current_line["pos_y"])
    		new_object.motion = Vector2(current_line["direction_x"], current_line["direction_y"])
    		
    
    		for i in current_line.keys():
    			if i == "filename" or i == "parent" or i == "pos_x" or i == "pos_y" or i == "direction_x" or i == "direction_y":
    				continue
    			new_object.set(i, current_line[i])
    	
    	save_game.close()
    
    	func save_level():
    		var save_game = File.new()
    		save_game.open("user://" + name + ".save", File.WRITE)
    	
    		var save_nodes = get_tree().get_nodes_in_group("save")
    	
    		for i in save_nodes:
    			var node_data = i.call("save");
    			save_game.store_line(to_json(node_data))
    	
    	save_game.close()
    
    	func delete_save_data():
    
    	
    		var dir = Directory.new()
    	
    		dir.open("user://")
    	
    		dir.list_dir_begin()
    
    		while true:
    			var file = dir.get_next()
    			if file == "":
    				break
    			elif not file.begins_with("."):
    				dir.remove(file)
    	
    		dir.list_dir_end()
  • @Megalomaniak said: Also worth a mention that the exported variables can have a default(/fallback) assigned in the same line that is defining the variable.

    export(type) var var_name = default_value

    Ok thanks, i managed to do it with a file .save now i have other problem, in the menu i have a "continue" button, now, i don't know what code should i use to tell that i want to load the "parent" scene from the .save file, any ideas?

  • @SIsilicon28 said: Ok, I have three things to say.

    Firstly, your code can be more readable if you surround them with "```". You should use "`" when surround a single code line or fragment. I'll format it for you this time. :)

    Secondly, if you look at the line that's calling new, you'll see that it's calling it from game_save_class which is an exported property. So the most likely reason why you're getting the error is because that property is null.

    Thirdly, it looks like your post got stuck in the moderation queue. Make sure that you have confirmed your email address. :)

    Ok thats nice and all, but how do i solve it?

  • i have this code :-1:

    extends Node
    
    export(Script) var game_save_class
    
    var save_vars = ["player_pos"]
    func _input(event):
    	
    	if event is InputEventKey and event.scancode == KEY_J:
    		save_world()
    	if event is InputEventKey and event.scancode == KEY_I:
    		load_world()
    
    
    
    func verify_save(world_save):
    	for v in save_vars:
    		if world_save.get(v) == null:
    			return false
    	
    
    
    func save_world():
    	var new_save = game_save_class.new()
    	new_save.player_pos = $Player.position
    	
    	var dir = Directory.new()
    	if not dir.dir_exists("res://saves/"):
    		dir.make_dir_recursive("res://saves/")
    	
    	
    	ResourceSaver.save("res://saves/save_1.tres", new_save)
    	
    	
    
    
    
    func load_world():
    	var dir = Directory.new()
    	if not dir.file_exists("res://saves/save_1.tres"):
    		return false
    		
    	var world_save = load("res://saves/save_1.tres")
    	if not verify_save(world_save):
    		return false
    		
    	$Player.position = world_save.player_pos
    	return true

    it gives me this error : Invalid call. Nonexistent function 'new' in base 'Nil'. PLS HELP IM LOSING MY MIND