Skip to content

Change Simple node scripts to instantiate themselves #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

dylanmccall
Copy link
Contributor

To support users adding SimpleCharacter and SimpleScoring as nodes, instead of as child scenes, add an _init function for each which loads the appropriate scene file and instantiates it.

https://phabricator.endlessm.com/T35545

@@ -19,6 +19,13 @@ const _POSITIONS_FOR_PLAYER = {
}


func _init():
var node = preload("res://addons/block_code/simple_nodes/simple_scoring/_simple_scoring.tscn").instantiate() as Node
node.replace_by(self, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I play the Pong game, it shows error:

E 0:00:00:0452   simple_scoring.gd:24 @ _init(): Condition "p_node->data.parent" is true.
  <C++ Source>   scene/main/node.cpp:2796 @ replace_by()
  <Stack Trace>  simple_scoring.gd:24 @ _init()
                 block_code.gd:56 @ _update_parent_script()
                 block_code.gd:14 @ _ready()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, I see how that happened. That's fixed in the newest set of commits.

@@ -52,6 +52,13 @@ func on_gravity_changed(new_gravity):
gravity = new_gravity


func _init():
var node = preload("res://addons/block_code/simple_nodes/simple_character/_simple_character.tscn").instantiate() as Node
node.replace_by(self, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I play the Pong game, it shows error:

E 0:00:00:0445   simple_character.gd:57 @ _init(): Condition "p_node->data.parent" is true.
  <C++ Source>   scene/main/node.cpp:2796 @ replace_by()
  <Stack Trace>  simple_character.gd:57 @ _init()
                 block_code.gd:56 @ _update_parent_script()
                 block_code.gd:14 @ _ready()

To support users adding SimpleCharacter and SimpleScoring as nodes,
instead of as child scenes, add an _init function for each which loads
the appropriate scene file and instantiates it.

https://phabricator.endlessm.com/T35545
@dylanmccall dylanmccall force-pushed the T35545-instantiate-simple-nodes branch from 065a94d to 5893a5a Compare July 17, 2024 16:44
@dylanmccall dylanmccall requested a review from starnight July 17, 2024 16:44
Comment on lines +5 to +8
func _init():
# Disable the SimpleCharacter _init function. We expect this script is
# already bound to _simple_character.tscn.
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@manuq manuq merged commit 9f6ab77 into main Jul 17, 2024
2 checks passed
@manuq manuq deleted the T35545-instantiate-simple-nodes branch July 17, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants