Listbox Container

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By pixelinkmedia

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")

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.

Dlean Jeans | 2019-06-11 10:16

Listbox Scroll Tutorial

Yeah… have case sensitive right on this one.

pixelinkmedia | 2019-06-11 10:21

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

Dlean Jeans | 2019-06-11 10:29

** 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 **

pixelinkmedia | 2019-06-11 10:38

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

Dlean Jeans | 2019-06-11 10:41

What is { } button.
And where is it?

pixelinkmedia | 2019-06-11 10:43

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

pixelinkmedia | 2019-06-11 11:04

Here:

enter image description here

Dlean Jeans | 2019-06-11 11:06

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 **

pixelinkmedia | 2019-06-11 11:07

:bust_in_silhouette: Reply From: Dlean Jeans

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

Changed that… still same error

pixelinkmedia | 2019-06-11 11:18

I just added an alternative solution.

Dlean Jeans | 2019-06-11 11:25

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

pixelinkmedia | 2019-06-11 11:26

Okay… that code got rid of the error,

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

pixelinkmedia | 2019-06-11 11:29

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

Dlean Jeans | 2019-06-11 11:46

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?

pixelinkmedia | 2019-06-11 13:39

Okay… I see the difference. from your gif

Fixed… and worked.

Thanks for your help!

pixelinkmedia | 2019-06-11 13:48

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. ¯\_(ツ)_/¯

Dlean Jeans | 2019-06-11 15:12

:bust_in_silhouette: Reply From: anamikasalujadnt

It’s Very Good for us to thank you