im working on a game on godot and im using a tutorial to code it

however, one of the code in the tutorial im using only works in godot 4.1, im using godot 4.2

so can anyone reply me the godot 4.2 version of this code? this is the code:

extends Resource

@export var scatter_targets: Array[Node2D]
@export var at_home_targets: Array[Node2D]

    kuligs2 Hm, I overlooked it inherits Resource. Might have something to do with the fact I was on a boat at the time.

    kuligs2 exports are supported, I used them on a CharacterSheet class. What is not supported it seems is the Node class.
    Referencing a Node likely points to a thing inside or outside the tree, but a resource doesn't have this context.
    Changing it to array is not likely to fix it (IDK, you can try and tell us if it does).
    here's some light reading: https://docs.godotengine.org/en/stable/classes/class_node.html

    SuperGibaLogan The real question is what are you trying to do? the solution to this problem depends on what you are trying to achieve. A solution would be to use a children Node instead of a Resource, but again, it depends on what you want it for.

    kuligs2 it works but i have 1 issue
    i cant assign things
    what it shows:

    what i want it to show (this image is from a tutorial btw, im using a tutorial to code my game):

      SuperGibaLogan Do tutorials only in the exact version of the engine the tutorial is made for. Otherwise you're potentially in for a lot of trouble. If your tutorial is for 4.1 why switch to 4.2?

        xyz how can you say that, when the only tutorial out there is in the version he is not using?...

        Thats like saying be healthy to someone with cancer.. 😃

        SuperGibaLogan try maybe any other type that is not node Array[refcounted] maybe? idk..

        @export var a: Array[NodePath] can be used with Resource classes but who knows in what ways will this "break" some other part of the tutorial code.

        @kuligs2 The problem is that people tend to use tutorials not to learn overarching concepts but to directly implement something into their game project. And we all know you must use only the absolutely newest version of the engine for your project. Otherwise, you're not "up to date" 🙂

          xyz People use tutorial to learn. Replicating the thing in your own project and see how it works, how it breaks things, this is a way to learn. Nobody gets born and already up to date with the latest godot docs in their head.. ofc you have to use logic and methodicalities to deduce the right outcome that you want to achieve.

          Also for newbs its not easy to understand where to get "older" versions of godot, and often its hidden behing multiple pages or at the bottom of the page where its not so obvious because we all been bombarder with too many information and when its given we often dicard it as noise or spam and overlok the details.

          • xyz replied to this.

            kuligs2 Poor sods. I wonder by what miraculous providence they're even able to locate a forum to ask about it.

            Jesusemora alright then
            i replaced "Resource" with "Node", but i still cant assign things
            btw im using the code so i can make the variables for the enemy character im making

              SuperGibaLogan Use 4.1. It's the easiest fix. Once you get it working in that version, then you can go on to adapting it to 4.2. Why needlessly overwhelm yourself by trying to learn stuff while at the same time trying to port stuff you've not yet learned?

              SuperGibaLogan did you static cast the exports back?
              @export var scatter_targets : Array[Node2D]

              or are you trying to access the values of a node from another node?
              again, what are you TRYING TO DO?

              SuperGibaLogan btw im using the code so i can make the variables for the enemy character im making

              so your variables are scatter_targets and at_home_targets
              what does this mean?
              I can only deduce that you want to assign the individual nodes that the "enemy" is going to interact with.
              this is a bad way of doing it. use groups instead.

              put your nodes into a group (the nodes and groups tab next to inspector), then in your enemy code you can get an array of nodes in that group with:

              var scatter_targets = get_tree().get_nodes_in_group("scatter_targets1")#lets say the nodes are in a group called scatter_targets1

              you can get_nodes_in_group whenever you need to do something with them, this method won't create a problem with deleted objects leaving behind an empty reference.

              there are other situations that would lead to other ways of doing things, why exactly do you need them in these 2 exports?