0 votes

I'm trying to use a grid to generate custom panel nodes. My Grid has the following function:

func spawn_panels(charType):
  var panelInit = null
  var panel = null
  if charType == PLAYER:
      panelInit = AllyPanel
  elif charType == ENEMY:
      panelInit = EnemyPanel

  for x in grid_s_x:
      for y in grid_s_y:
          panel = panelInit._init(x, y)
          panel.position = map_to_world(Vector2(x, y)) + cell_size / 2

AllyPanel and EnemyPanel extends CusPanel, which in turn extends Area2D

When spawn_panels is ran, I get the following error:

Invalid set index 'position' (on base: 'Nil') with value of type 'Vector2'.

I'm quite new to the engine, so if anyone can point me to what I did wrong I'd appreciate it. Thanks!

in Engine by (21 points)

The error is because panel is null, you have setted it as null, but then you do a misterious panel = panelInit._init(x, y) I guess trying to give it a value. What does it do?

1 Answer

0 votes

Based on the error, it sounds like panel is null. You should verify that it contains the expected reference.

by (12,290 points)

I was able to get pass the reference by calling new() instead; thanks!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.