Error: Scene name cannot be reserved word - react-native-router-flux

I'm trying to give a Scene the key 'create', but I keep getting an error saying
Scene name cannot be reserved word: create
Is there a way to allow a Scene to be called 'create'?

Related

Godot: How to move KinematicBody2D node from one scene to another

I want to move my Player node (KinematicBody2D) from one scene to another. My code successfully moves Node2D node, but fails with KinematicBody2D node.
I have two Location scenes (inheriting from base Location scene) with the following structure:
FirstLocation (inherits Location)
- YSort
- Player
In the base Location scene I have two methods:
func add_player(player: Player):
get_node("YSort").add_child(player)
func remove_player() -> Player:
var player = get_node("YSort/Player")
get_node("YSort").remove_child(player)
return player
In GameWorld scene I store the possible locations inside a dictionary and the moving of the player happens inside change_location() function:
onready var _locations = {
Location.FOO: $CurrentLocation,
Location.BAR: load("res://locations/Bar.tscn").instance(),
}
onready var _current_location = $CurrentLocation
func change_location(location: int):
var player = _current_location.remove_player()
remove_child(_current_location)
_current_location = _locations[location]
add_child(_current_location)
_current_location.add_player(player)
The switching of the location works
The moving of the player also works in case the player is plain Node2D.
But when Player is KinematicBody2D then the game simply crashes, giving me no hint as to what's causing the problem.
The code works without crashing when I comment out the last line:
_current_location.add_player(player)
...but of course then the player simply doesn't get added to the other scene.
I verified that the player does get removed from the scene.
I tested with a dummy scene (which only contains KinematicBody2D as root node and a simple Sprite as a single child) instead of my actual more complex Player scene to make sure it's not related to any other code I might have in my Player scene. Node2D as root works, KinematicBody2D crashes. Must have been a fluke. Tested again and now both work, so there must be something different in my Player object.
I tried adding the Player node as a direct child of Location node (not having a YSort node in the middle) - nope, still crashes.
I tried setting the position/global_position of player before/after adding it to new scene - no difference.
I'm able to create new Player scene instance and add it to new location.
What might it be in KinematicBody2D that prevents me from moving it from scene to scene?
Found a solution, but I don't know why it works.
I was performing the location change as a response to Area2D.body_entered signal. I triggered my own signal "location_change" and then called the change_location() function in another part of the code in response to it.
Adding a tiny timeout (0.00000001 seconds) before doing the location change solved the issue. However I have no idea why, and I'm pretty sure adding timeouts is not a proper way to solve this problem.
I'm having trouble visualizing the situation. However, given that the problem happens when removing and adding a physics body, and that "body_entered" was involved, and that the solution you found was adding a time out…
Sounds like the issue was removing the physics body while Godot was still resolving physics response. And then the solution was to wait until the next frame.
You could wait until the next graphics frame with this:
yield(get_tree(), "idle_frame")
Or until the next physics frame with this:
yield(get_tree(), "physics_frame")
Which would be better than some arbitrary small timeout.
Alternatively, you could also make the signal connection deferred.
If you are connecting from the UI, there will be an "advanced" toggle in the "Connect a Signal to a Method" dialog. Enabling "advanced" toggle will reveal some extra including making the connection deferred.
If you are connecting form code, you can accomplish the same thing by passing the CONNECT_DEFERRED flag.

Why is my game scene getting errors when the main scene is actually the menu in Godot

I am adding a main menu to my game. The thing I am doing is adding them in a scene and then changing the scene to the game scene. However, my game has errors which belong to other scenes that do not have an instance in the existing scene. I get errors such as:
Invalid get index 'HasEntered' (on base: 'null instance').
My entire project is here: https://github.com/Ripple-Studios/Godot-Wild-Jam-36-Game-Ripple-Studios
I would appreciate if someone would help me.
Thanks,
I had a look at the linked code.
What is happening is that the practice of getting nodes of the parent has come back to bite you. I'm talking code that looks like this:
get_parent().get_node(...)
You have an scene (HospitalScene.tscn) instanced in your main scene (MainMenu.tscn), which has code similar to the shown above.
The particular error you refer to comes from code that looks like this:
func _on_Area2D_body_entered(body):
var HospitalPosition = get_parent().get_node("Hospital")
if HospitalPosition.HasEntered == true:
HospitalPosition.isInHospital = false
This code is firing at the start because the Area2D is overlapping an StaticBody.
The code is trying to get a sibling "Hospital" which does not exist in the scene tree. And thus HospitalPosition is null. And trying to access HospitalPosition.HasEntered when HospitalPosition is null results in the error you mention:
Invalid get index 'HasEntered' (on base: 'null instance').
The scene is trying to reach a node outside of itself. And there is no guarantee that the scene will be instanced where such node is available. Thus, in each and every case of get_parent().get_node(...) this could happen.
In fact, when running the game, I get four error that look like this (but with different paths):
E 0:00:01.494 get_node: (Node not found: "Hospital" (relative to "/root/CanvasLayer/ParentSprite/Control").)
<C++ Error> Condition "!node" is true. Returned: nullptr
<C++ Source> scene/main/node.cpp:1325 # get_node()
<Stack Trace> HospitalScene.gd:28 # _on_Area2D_body_entered()
You could use get_node_or_null instead of get_node and check for null.
You could also export NodePath variables instead of hard-coding the paths.
Better decoupling strategies than checking if instances are valid include:
Connect to the signal from outside the scene. It is a common pattern in Godot to call down the scene tree, and signal up the scene tree. See Node communication (the right way).
Connect all the signals through an Autoload (singleton). Which is another common pattern in Godot called a Signal Bus or Event Bus. See Best practices: Godot GDScript - Event Bus.

Mapbox SDK - App crashes when using animateCamera during click event

I'm working with Mapbox SDK for Android and I'm doing a simple task of "click and move" but for some reason whenever I click on a location and the camera moves to the location, the app crashes with the following error.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.MapboxMap.animateCamera(com.mapbox.mapboxsdk.camera.CameraUpdate, int)' on a null object reference
The error then points to this line.
mapboxMap.animateCamera(CameraUpdateFactory
in
mapboxMap.animateCamera(CameraUpdateFactory
.newCameraPosition(new CameraPosition.Builder()
.target(new LatLng(latLng))
.zoom(13)
.build()), 1500);
The LatLng is not empty. I made sure to validate if the coordinates are being passed and they are.
As a matter of fact, even if I hardcode the coordinates (lat / lng) it still crashes.
Note: This happens with moveCamera(), easeCamera() and animateCamera().
'void com.mapbox.mapboxsdk.maps.MapboxMap.moveCamera(com.mapbox.mapboxsdk.camera.CameraUpdate)' on a null object reference
'void com.mapbox.mapboxsdk.maps.MapboxMap.easeCamera(com.mapbox.mapboxsdk.camera.CameraUpdate)' on a null object reference
However, one thing to note is that if I place that code in the onMapReady() instance, the map loads with the camera positioned where the coordinates point to but if I perform a click event to trigger the function to move the camera to where I clicked, it crashes.
Another thing I'd like to mention is that when I click the camera actually GOES to the location but it crashes right away. The reason I know this is because when the android studio emulator tries to "recover the app", it shows the map on the location it was meant to go to.
Any ideas why this happens?
other functions like forward and reverse geocoding work just fine when I perform a click event.
The problem I was having which was making the function not recognize the map itself and thus returning NULL was:
#Override
public void onMapReady(#NonNull final MapboxMap mapboxMap) {
mapboxMap = mapboxMap; //<=== THIS HERE WAS THE PROBLEM.
//It should be this.mapboxMap = mapboxMap
..........
I have the mapboxMap declare as a global in the activity but when the map initialized, it was assigning itself to the global variable and keeping it within the scope of the onMapReady and it was impossible for the function that moves the camera to locate the it all.
in any case, it all works now.

Don't know how to reference other scene into script

I can't link SliceAndCoagulatorScene to the script to set its visible to false I've tried get_node, $res://...
extends Node2D
onready var main_scene = get_node(".")
onready var SliceAndCoagulatorScene = get_node("_________")
func _ready():
main_scene.visible = true
This is what I would like to put after :
SliceAndCoagulatorScene.visible = false
How could I do this, any help is appreciated
For clarity: A res:// path does not exist in the scene tree, it exists in the virtual file system. As such, you cannot access it from get_node. Because get_node works on the scene tree, thus you need to load and instantiate the scene in the scene tree first.
If you have added the scene to the scene tree in the editor, then it will load it and instantiate it for you, and there will be a path you can put in get_node... But it will not be a res:// path, because, again, a res:// path exists in the virtual file system.
You give res:// paths to load (or load_interactive, see Background loading, or change_scene), not to get_node.
Now, either you are trying to target a scene that is loaded or one that isn't.
If your other scene is not loaded, you need to load it (load or load_interactive) which gives you a PackedScene, instantiate it (instance) which gives you a Node. At which point you have a reference, go ahead an use it. You probably want to add to the scene tree (e.g. add_child).
For example, here we attach the new scene to the root (which may or may not be what you want, in particular in the face of changing scenes, but that is another topic):
func _ready():
var packed_scene = load("res://something.tscn")
var scene_node = packed_scene.instance()
var root = get_tree().get_root()
root.add_child(scene_node)
scene_node.visible = false # or whatever
I will suggest to use a PackedScene export:
export(PackedScene) var packed_scene
onready var scene_node = load(packed_scene).instance()
func _ready():
var root = get_tree().get_root()
root.add_child(scene_node)
scene_node.visible = false # or whatever
Then in the inspector panel you will see a new property "Packed Scene" (Godot auto capitalizes the name) where you can specify the scene from the file system. Plus, if you move scenes in the file system in the editor, the editor will update the path for you.
Note: you may or may not want to add them to get_tree().get_root(). Other options include adding it to get_tree().get_current_scene(), get_owner(), get_parent() and to self.
On the other hand, both your scenes are already loaded in the scene tree. In which case, there is a path from one node to the other, which you can put in get_node. If your target scene is not a child, you probably want to go up a few levels with ... However, I would advice against hard-coding such path.
Instead, you will get a lot of leverage of the following:
export(NodePath) var target_scene
onready var scene_node = get_node(target_scene)
Then in the inspector panel you will see a new property "Target Scene" where you can specify where in the scene tree the node you want to access is. Plus, if you move the nodes around in the scene tree in the editor, it will update the path for you.
Then you can do:
func _ready():
scene_node.visible = false # or whatever
Note: If you don't know if the scene is loaded. You might be interested in using find_node. Control also provide a get_node_or_null.

I have a problem with sceneManager.LoadScene

I have this piece of code
if(personajeCreado == "0")
{
Debug.Log("hi");
UnityEngine.SceneManagement.SceneManager.LoadScene("CreandoPersonaje");
Debug.Log("bye");
}
In the debugger I only read hi, but my scene does not change, there are no errors, there is nothing to indicate a problem. please help.
Possibilities:
- You do not have the target scene included in the build
- The name of the scene is not correct (I would copy the name from the scene file itself)
- Your target scene is same as your starting scene and you did not notice the change of scene
- You have error message in your console but you have disabled the error message view and did not see the actual error

Resources