hello,
i have plugIN node, with a set of vars, one of them is an array.
On the other side in this node inspector i have an instance with an itemList node.

iam trying to set the item names in the itemList but i always get a Nil value ?

res://inspector/inspector.gd:61 - Invalid get index '0' (on base: 'Nil').

editor plugIn node

@export var layers = {
	'Lnum': [ {} ]
}
#-----------------------------------------------
#-----------//--inspector--//-------------------
#-----------------------------------------------

var sav_tl_W: int = 32;
var sav_tl_H: int = 32;
var sav_cv_W: int = 1024;
var sav_cv_H: int = 768;

var layerName: Array = ["background " , "panel", "layer1"]; #-----here



func _get_property_list(): 
	return[
		{
		"name": "sav_tl_W",
		"type": TYPE_INT,
		"usage": PROPERTY_USAGE_STORAGE
		},
		{
		"name": "sav_tl_H",
		"type": TYPE_INT,
		"usage": PROPERTY_USAGE_STORAGE
		},
		{
		"name": "sav_cv_W",
		"type": TYPE_INT,
		"usage": PROPERTY_USAGE_STORAGE
		},
		{
		"name": "sav_cv_H",
		"type": TYPE_INT,
		"usage": PROPERTY_USAGE_STORAGE
		},
		{
		"name": "layerName", #-----here
		"type": TYPE_ARRAY, #-----here
		"usage": PROPERTY_USAGE_STORAGE #-----here
		}
	]

inspector.tscn

#-PlugTileDrawNode2 equal the node above

func _ready():
	fliterPopUP.tlDrawNode = PlugTileDrawNode2;
	
	if ( PlugTileDrawNode2 != null ):
		tl_W.value = PlugTileDrawNode2.sav_tl_W;
		tl_H.value = PlugTileDrawNode2.sav_tl_H;
		cv_W.value = PlugTileDrawNode2.sav_cv_W;
		cv_H.value = PlugTileDrawNode2.sav_cv_H;
		
		var listSize = itemList.get_item_count();
		var layerMax = PlugTileDrawNode2.layers.Lnum.size();
		
		for n in range( 0, layerMax ):
			#itemList.add_item("     layer " + str(n) );
			itemList.add_item( PlugTileDrawNode2.layerName[n]  );

Is there a way to pass the names in the array on the other side ?
this line of code works -> #itemList.add_item(" layer " + str(n) );
however when i try to put the array in there -> itemList.add_item( PlugTileDrawNode2.layerName[n] );
Iam always getting an error ?

res://inspector/inspector.gd:61 - Invalid get index '0' (on base: 'Nil').

  • xyz replied to this.

    jonSS You really need to learn to debug your code using print statements.

    For start print PlugTileDrawNode2 and PlugTileDrawNode2.layerName in _ready().

    If one of them prints null, you either accidentally assigned null to it somewhere in the code or its initialization code has not yet been executed. In the former case search for all appearances of those names throughout the code (Search>Find in Files). In latter case, put more print statements all over your initialization code to see what gets initialized when. Debugging 101.

    Also try removing the entry for that array form _get_property_list() just to make sure that's not the source of the problem.
    You could have somehow assigned null to it and it got saved with the scene since property's STORAGE flag is set, and its value now behaves like an @export value. So the saved null value will override the value assigned at declaration. To check the value in the inspector, temporarily add EDITOR usage flags, as I described in your previous question. Or simply make that property @export while debugging. Or look into tscn file.

    I could debug this for you by looking at the whole thing but at this point I should probably start charging you for debugging services 😉

      xyz thanks,
      its already working...
      Ive restarted the editor and it got fixed, i just didnt knew if it was possible to add it this way to '_get_property_list()'

      I did remove the array from _get_property_list() and was still printing a 'Nil' restarting fixed it !!!

      the only thing iam missing its this var:

      @export var layers = {
      	'Lnum': [ {} ]
      }

      Iam ok with leaving the var in the editor, its good to see the images in the dictionary, and also the ones that are all transparent ( alpha 0 )
      but if the user presses the reset button

      everything crashes...

      Do you know if there's way to make this var non editable or remove the reset button
      Iam not really sure on how to set this var in _get_property_list() ?

      [edit]
      Maybe its something like this:

      var layers = {
      	'Lnum': [ {} ]
      }
      
      func _get_property_list(): 
      	return[
      		{
      		"name": "layers",
      		"type": TYPE_DICTIONARY,
      		"usage": PROPERTY_USAGE_STORAGE
      		}

      but i think it would be better to leave the var there, just make it non editable

      • xyz replied to this.

        jonSS If you want to make something non-editable in the inspector add PROPERTY_USAGE_READ_ONLY flag to usage flags.
        If you want to prevent revert, implement _property_can_revert().

        Read the reference for the Object class. Plenty of useful stuff there 🙂

          found it, this will makes the var non editable in the editor

          var sav_tl_W: int = 32;
          
          func _get_property_list(): 
          	return[
          		{
          		"name": "sav_tl_W",
          		"type": TYPE_INT,
          		"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_READ_ONLY
          		}
          	]

          xyz thanks,
          i was using 'PROPERTY_USAGE_READ_ONLY' but was trying without 'PROPERTY_USAGE_STORAGE '

          If you want to prevent revert, implement _property_can_revert().

          "revert" must be the button with a circle arrow ? that resets the value ?
          but it seems to be working this way the value is greyed out and cant be edited ( when i press the arrows UP and DOWN the value doesnt change )
          I used 'sav_tl_W' for testing it...

          • xyz replied to this.

            jonSS Yeah revert is for that arrow. If you want to get rid of the arrow but still keep the property editable implement _property_can_revert(), wasn't that what you asked?

            In your case, you always need to have the STORAGE flag. Otherwise the values won't be saved. This flag has nothing to do with the appearance of the property in the inspector. It only regulates serializing (aka saving) its value into scene file.

              xyz the revert arrow it seems to automatically disapear

              var layers = {
              	'Lnum': [ {} ]
              }
              
              func _get_property_list(): 
              	return[
              		{
              		"name": "layers",
              		"type": TYPE_DICTIONARY,
              		"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_READ_ONLY
              		},
              		{
              		"name": "sav_tl_W",
              		"type": TYPE_INT,
              		"usage": PROPERTY_USAGE_STORAGE
              		},
              		{
              		"name": "sav_tl_H",
              		"type": TYPE_INT,
              		"usage": PROPERTY_USAGE_STORAGE
              		},
              		{
              		"name": "sav_cv_W",
              		"type": TYPE_INT,
              		"usage": PROPERTY_USAGE_STORAGE
              		},
              		{
              		"name": "sav_cv_H",
              		"type": TYPE_INT,
              		"usage": PROPERTY_USAGE_STORAGE
              		},
              		{
              		"name": "layerName",
              		"type": TYPE_ARRAY,
              		"usage": PROPERTY_USAGE_STORAGE
              		}
              	]

              it doesnt show when i add new layers, like it was doing before

              but the editor is getting really slow ( it stops for about 3 seconds ) when i press the "Lnum" array containing the dictionary, layer1, 2, 3, etc... ( it doesnt really matter the number of images, its the same time always )

              but its fine now... i dont think anyone will be pressing there.
              1st click -> Dictionary (size 1)
              2st click -> 'Lnum' Array (size 6)
              3st click -> Dictionary (size 40)

              • xyz replied to this.

                jonSS the revert arrow it seems to automatically disapear

                Of course it disappears if the property is read only. _property_can_revert() is for when you need an editable but non-revertable property.

                jonSS but the editor is getting really slow

                Likely because you're doing something you shouldn't due to not fully understanding how a plugin should operate. Try to identify bottlenecks by gradually commenting out suspicious parts of code.

                  xyz thanks, everything should be working, now.
                  ( execpt for when the user selects tiles that are drawn on screen, when the user changes the "tile size"... sav_tl_W / sav_tl_H, the width and height of the tile is no longer 32, 32.. there could 32, 100, 57, tiles in there )

                  I can almost start remaking this thing again working with less code. And "bottlenecks" should be more easy to solve.
                  But i think this is just a testing stuff..lol,
                  The reason i did it this way was beacuse this was the hardest way...
                  The normal way and more easy way is to add viewports instead of "layers" 'array/dictionaries', and merge everything into one image at the end. That way there would be no images lost in the gpu ram.

                  Making a tileDraw with viewPorts after making this one should be really easy.