The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I am going through a tutorial. But the project generate errors because I believe the tutorial is outdated from 2017

I first try to pre-load a scene2 that contains a list item

I try to get node from this preloaded scene
But, error says node not found "number" & "Label"

What is the correct way to get a node or I suspect that the preload scene 2 is not loading.

CODE:

const ListItem = preload("listitem.tscn")
var listIndex = 0

func additem( value):
    var item = ListItem.instance()
    listIndex += 1
    item.get_node("number").text = str( listIndex )
    item.get_node("Label").text = value
    $ScrollContainer/list.add_child(item)

func _ready():
    for i in range(10):
        additem("List Text String")
in Engine by (54 points)
edited by

What's the tutorial you're following?

Code seems normal to me. Check if the nodes' names are correct. Note that it's case-sensitive.

Listbox Scroll Tutorial

Yeah... have case sensitive right on this one.

Add item.print_tree_pretty() to your additem and paste the output here. Might help seeing what's wrong.

** Debug Process Started **
OpenGL ES 3.0 Renderer: GeForce GT 640/PCIe/SSE2
┖╴Node2D
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@2
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@3
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@4
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@5
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@6
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@7
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@8
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@9
┖╴Panel
┠╴number
┖╴Label
┖╴@Node2D@10
┖╴Panel
┠╴number
┖╴Label
** Debug Process Stopped **

Use the { } button. The tree format is broken without it.

What is { } button.
And where is it?

This is the exact error on lines "number" & "Label" of get_node...

Invalid set index 'text' (on base: 'null instance') with value of type 'String'.

On the Error(s) tab of debugger it just says...

E 0:00:01:0064 Node not found: number

Here:

enter image description here

Oh... the code button, I assume you meant in Godot itself

** Debug Process Started **
OpenGL ES 3.0 Renderer: GeForce GT 640/PCIe/SSE2
 ┖╴Node2D
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@2
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@3
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@4
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@5
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@6
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@7
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@8
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@9
    ┖╴Panel
       ┠╴number
       ┖╴Label
 ┖╴@Node2D@10
    ┖╴Panel
       ┠╴number
       ┖╴Label
** Debug Process Stopped **

2 Answers

0 votes

Based on your scene tree, seems like you're using a Node2D as the root note.

The solution: In the Inspector, on the Panel node, Right Click > Make Scene Root.

Alternative solution: Use find_node

item.find_node("number").text = str( listIndex )
item.find_node("Label").text = value
by (4,246 points)
edited by

Changed that... still same error

I just added an alternative solution.

Hey... thanks for helping.
I had a stroke a few months ago, and i get very dizzy.

So, I need take a nap for a couple hours, so i am taking off.

If you like, you don't have too.
But, here is my project zipped up.

ScrollList project

Okay... that code got rid of the error,

But it only shows 1 list item when it should be 10

I'm sorry, it seems that your condition might be affecting your ability to follow closely to tutorials, which is pretty much causing this and your last question's problem. Hope you get well soon!

Anyway, here's a GIF showing that my first solution works:

GIF

Sir,

1) I didn't do anything wrong on the first... the tutorial was wrong.

2) The code you gave me got rid of the error... the demo started fine.

The only thing different is that it doesn't show all items.

If you are using my project, then what is different??
Why is it not working for me??

If you made that tutorial from the video... then can you post it, so I can download it?

Okay... I see the difference. from your gif

Fixed... and worked.

Thanks for your help!

Tutorials might be incorrect, but most of the time it's unlikely.

Sometimes you just need to throw your ego out of the window and admit that you might be wrong. So that you can learn.

Just saying, I'm no one to teach life lesson. ¯\_(ツ)_/¯

0 votes

It's Very Good for us to thank you

by (14 points)
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.