REVBENT Do new.data. The variable new is a reference to the node that contains the property data. Upon instantiation, pass this reference to anyone who needs to access data.

Btw you should avoid using the word new to name your variables. It's a name of a built in method in Object class from which all other classes are inherited.

what if i have multiple of the same instance? but want that data to be individual?

  • xyz replied to this.

    Say i press the button 3 times, but want one red, one blue, etc, save/load, and maintain data integrity to the specific node.

    Am i just trying to do too much, too easily?

    • xyz replied to this.

      REVBENT If the script is creating a resource instance via DATA.new(), the each scene instance will create its own copy of the DATA object.

      REVBENT Here's a simple example to play with:
      Resource class:

      class_name Data extends Resource
      var foo = 1

      Instantiated scene class (scene.gd):

      extends Node
      @export var data = Data.new()

      Script that does scene instantiation:

      extends Node
      func _ready():
      	var s1 = load("res://scene.tscn").instantiate()
      	var s2 = load("res://scene.tscn").instantiate()
      	print(s1.data)
      	print(s2.data)

      You should get a printout of two different Data resource objects:

      <Resource#-9223372008316730102>
      <Resource#-9223372008132180722>

      In the case you don't do Data.new() in the scene script, but instead you create and assign a Data object in the editor (to an exported property) that resource will be shared between all scene instances.
      However if you enable resource_local_to_scene flag for that resource, the engine will automatically duplicate it when instantiating the scene.

      ok i will try to figure this out, i am struggling to visualize this. Maybe some coffee and a break will help it sink in.
      Thanks for the heads up too with naming conventions. I actually do use a better naming scheme for everything, but just for example sake i typed that stuff.
      In my global script how should i reference the created node? I was sending the "self", the getnode(self), getnodepath(self)... as a NodePath in my global script.
      I would then try to say in process:
      if Input.action....(Leftmouse):
      var scene = <path of node i was sending>.data
      scene.Name = globalname
      .....and the above was not working.... so i think i was trying to access the property properly potentially (see what i did there 😛)....
      what i think i am doing wrong is referencing that specific node (created at run time) in the script.

      seriously thanks for taking your time. i know we all got shtuff to do!

      how do i load the:
      <Resource#-9223372008132180722>
      in the global script.....
      i can get my node to reference that and send it. i think i already did.
      so in the global i want to load that resource from reference at runtime, without declaring the variables in _ready()... because the number will change depending how many objects i instantiate or delete.... as in i wont know "S1" to "Sx) at run time/change with load data

      • xyz replied to this.

        REVBENT By "global script" you mean autoload/singleton?

        or do i say something like:

        var object = <Resource#-9223372008132180722>
        object.Name = globalName

        yes.... autoload. I figured i was safest to use that to hold the information and have a separate window to change data... with the singleton acting as the "middleman"

        • xyz replied to this.

          REVBENT Who calls the code in the autoload script that then access the resource? Whoever calls it should also supply a reference to the instantiated scene node or its resource object.

          BTW... i have read you explaining instantiate stuff (maybe the above example???)... as well as many other posts. I really do try to source other places/archives best i can.
          With that said...
          You put some serious time into this site. Its highly impressive and very appreciated.
          I know i say this a lot... but i feel it should be.... THANK YOU!

          The object scene itself is setting a global variable when Input to its <id/path/self>.
          In the autoload i have an export var for <path/id/self>.
          I am trying to create a global func to set a value (data) in another scene (controller scene) that changes the values of the "data"
          The global script have separate set of variables to be set to what the new_data.
          If the player chooses to keep "new_data" it will save the changes to objects "data"...
          If the player chooses to discard i wont have touched the original data.
          I was thinking to have more types of controllers or objects eventually and or access them between scenes.
          I think that is how i need to structure handling data that's created/edited at run time???

          • xyz replied to this.

            REVBENT To complicated for my brain 😃
            Can you explain what are you trying to achieve? Without any technicalities, or ways you tried to do it. Just what needs to happen "on the outside", from the player perspective.

            I want to push a button in game: #MAIN scene
            create object(1)
            push button;
            create object(2) #just for example it may be other objects... they are added with button in game
            click object(1)
            load object DATA into "Menu" #Controller scene
            change object(1) DATA via buttons/sliders in "Menu"
            close the "Menu" saving the DATA(new) ....or... close the "Menu" keeping DATA(old)
            switch scenes back to "MAIN" where the object(1) property has been updated to DATA(new) #MAIN scene again

            I want to load data from object(1) into "controller scene".
            Change the data in the "controller scene". SAVE or NOT
            Switch to Main scene and keep the data.

            I think i am not referencing the created node or its properties correctly in my code.

            • xyz replied to this.

              i can do all of this if i have the scenes in the scene tree and access them by their path. All that works for me, but when trying to do so "dynamically" in game (scene added to tree in game), i can't get the nodes reference to work in my global scene.

              REVBENT No, not like that. Forget data, controllers and scenes. Just describe what the player sees and how they're supposed to interact with it. In simple non technical language.

              i will try to refine what i have thus far and hopefully... have something working (ish) to help show what i want to do. i KNOW everything i do will be able to be seriously improved.
              you will totally understand what i'm going for when you see it. Its more than i should have done to learn UI, but its been a fun uphill lesson.

              Game wise, you are the "player" and the data IS what they interact with 😛

              click button.
              make object.
              click object.
              change several different types of data attributed to that object, color/size/labels/etc
              have main screen show the related changes and save the changes/load the changes
              sort the data based off the objects attributes when pressing button.

              • xyz replied to this.

                REVBENT So when "click object" happens, you want a global script to get this object and alter its data. You just don't know how to tell to the global script which object has been clicked?

                yes!
                and i would like to change that data/save changes to data.
                i've tried so many different ways now i'm so turned around.

                • xyz replied to this.