0 votes

I need help

im making a puzzle game in GD script and have my code from a video that helped me create this although the video was made over 3 years ago and some of my code doesn't work.
if im to comment out to see the next line that includes "img" gives me an error message saying "Invalid get index '0' (on base: 'Array')"

Could someone please give me some help on how to fix this and if it's because of my images name? because the name is numbers.

my entire code is:

extends Node2D

var map = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]
var imgNode = load("img.tscn"); var img = []
var move = Vector2(0,0); var speed = 4 # 1,2,4

func _ready():
for n in range(16):
img.append(imgNode.instance()) ## <-------- is rooted and says attempt to call function 'instance' in base 'nulll instance' on a null instance

    img[n].set_frame(n) ## <------ says Invalid get index '0' (on base: 'Array').
    for y in range(4):
        if map[y].find(n) != -1:

func step(key,dir):
if Input.iskeypressed(key) and move == Vector2(0,0) or move == dir:
for y in range(4):
if map[y].find(15) != -1:
var pos = Vector2(y,map[y].find(15)) + dir
pos.x = min(max(pos.x,0),3); pos.y = min(max(pos.y,0),3)
if img[map[pos.x][pos.y]].get
pos() != Vector2(map[y].find(15)100,y100):
move = dir
img[map[pos.x][pos.y]].setpos(img[map[pos.x]].getpos() - Vector2(dir.yspeed,dir.xspeed))
else: map[y][map[y].find(15)] = map[pos.x][pos.y]; map[pos.x][pos.y] = 15; move = Vector2(0,0)

func fixedprocess(delta):

in Engine by (14 points)
edited by

1 Answer

0 votes

try something like this;

var imgNode = load("res://img.tscn")

load is need correct node path

by (71 points)

it's still rooting my img.append(imgNode.instance()) saying attempt to call function 'Instance' in base 'null instance' on a null instance.

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 Frequently asked questions and 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 [email protected] with your username.