Godot 4.0: Metadata Demonstration
HTML-код
- Опубликовано: 25 авг 2024
- Metadata can be useful for adding properties without even attaching a script. Very similar to Construct's instance variables.
To access, use get_meta("name") or set_meta("name", value)
@export var value_to_compare : String
@export var satisfactory_value : float
var children_succeeded : int = 0
func _ready():
if get_child_count() == 0: return
for c in get_children():
if c.get_meta(value_to_compare) is greater than or == satisfactory_value:
children_succeeded += 1
result()
func result():
if children_succeeded == 0:
print("None have succeeded")
elif children_succeeded is greater than 0:
print("At least one has succeeded")
elif children_succeeded == get_child_count():
print("All have succeeded")
What am I looking at? What am I supposed to pay attention to when you run the game?
debug log
This is a terrible "tutorial".
Thank you bunches! This has been very helpful in an endless runner I'm working on, so that each incoming Platform can have its own position modifier attached to it without having to make a unique script for each Platform.
ive tried so many different ways of writing the metadatas key and i keep getting nulled
May I see the code?
@@paintmeteor3834 func _on_tile_map_child_entered_tree(node):
var ids = {"0": "sponge"}
if node.get_meta_list():
node.connect("body_entered", Callable(self, str(ids.get(node.get_meta("ID")))+"_contact"))
print(str(ids.get(node.get_meta("ID"))))
im trying to use it to tie nodes to appropriate functions
480p realy? :(
ikr.
i live with 360p, be greatful
Re humilde el pibe.
How do you even access it through a script?
To access meta with a script, use the get_meta() function.
@@paintmeteor3834I use “get_meta()” but I get the Errors
“teleporter.gd:3 @ implicit_new(): The object does not have any ‘meta’ values with the key ‘Destination’” and “Invalid get index ‘position’ (on base: ‘Nil’).”
Why is it not acknowledging me creating metadata from the editor?? My metadata essentially is null for some reason???
The meta you're accessing might be case-sensitive.
@@paintmeteor3834Confirmed just now this is not the case. My Script tab is even autocompleting with the correct spelling and capitalization.
@@paintmeteor3834 and set_meta