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")

Комментарии • 19

  • @raysandrarexxia941
    @raysandrarexxia941 3 месяца назад +7

    What am I looking at? What am I supposed to pay attention to when you run the game?

  • @DisDudeDraws
    @DisDudeDraws 10 месяцев назад +1

    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.

  • @catharsis9789
    @catharsis9789 9 месяцев назад +3

    ive tried so many different ways of writing the metadatas key and i keep getting nulled

    • @paintmeteor3834
      @paintmeteor3834  9 месяцев назад

      May I see the code?

    • @catharsis9789
      @catharsis9789 9 месяцев назад

      ​@@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

  • @ritor_msg
    @ritor_msg 9 месяцев назад +7

    480p realy? :(

  • @alfredogodoy6854
    @alfredogodoy6854 4 месяца назад

    Re humilde el pibe.

  • @Zly_u
    @Zly_u 11 месяцев назад

    How do you even access it through a script?

    • @paintmeteor3834
      @paintmeteor3834  11 месяцев назад

      To access meta with a script, use the get_meta() function.

    • @repentmfgaming
      @repentmfgaming 11 месяцев назад

      @@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???

    • @paintmeteor3834
      @paintmeteor3834  11 месяцев назад

      The meta you're accessing might be case-sensitive.

    • @repentmfgaming
      @repentmfgaming 11 месяцев назад

      @@paintmeteor3834Confirmed just now this is not the case. My Script tab is even autocompleting with the correct spelling and capitalization.

    • @ltecheroffical
      @ltecheroffical 10 месяцев назад

      @@paintmeteor3834 and set_meta