#Following tutorial:stuck on function that wants object not Array

51 messages · Page 1 of 1 (latest)

neon dagger
#

https://www.youtube.com/watch?v=V79YabQZC1s

extends PanelContainer

const SLOT = preload("res://Inventory/slot.tscn")

@onready var item_grid = $MarginContainer/ItemGrid

func _ready() -> void:
    var inv_data = preload("res://test_inv.tres")
    populate_item_grid(inv_data.slot_datas)

func populate_item_grid(inventory_data: InventoryData) -> void:
    for child in item_grid.get_children():
        child.queue_free()
        
    for slot_data in inventory_data.slot_datas:
        var slot = SLOT.instantiate()
        item_grid.add_child(slot)
        
        slot.slot_clicked.connect(inventory_data.on_slot_clicked)
        
        if slot_data:
            slot.set_slot_data(slot_data)
    

Invalid type in function ' populate_item_grid' in base 'PanelContainer (inventory.gd)'. Cannot convert argument 1 from Array to Object.

Basic FPS Controller Code: https://pastebin.com/yJwwpkCu
Shikashi's Fantasy icons Pack: https://cheekyinkling.itch.io/shikashis-fantasy-icons-pack

Follow along as I code the structure of an RPG type inventory system in Godot 4.

=== Intro / Setup ===
0:00 Intro
0:45 Project Setup

=== Resource Data Structure ===
2:50 Item Data Resource
4:27 Slo...

▶ Play video
#

Following tutorial:stuck on function that wants object not Array

tall horizon
#

what does slot_datas return?

neon dagger
#

@export var slot_datas: Array[SlotData]

tall horizon
#

it needs to compile to run. try taking out the type annotations (the : Type bit). that should get it to compile

neon dagger
#

this one? inventory_data: InventoryData

tall horizon
#

which ever is causing the compile time error

neon dagger
#

i dunno, I just pressed undo until it stopped doing the error

#

maybe the tutorial has an error in it

tall horizon
#

I remember helping someone else a bit ago who used this tutorial, so it could be that

neon dagger
#

@tall horizon the tutorial removes the 3 lines here but when I do it, I get an error https://youtu.be/V79YabQZC1s?t=2113

Basic FPS Controller Code: https://pastebin.com/yJwwpkCu
Shikashi's Fantasy icons Pack: https://cheekyinkling.itch.io/shikashis-fantasy-icons-pack

Follow along as I code the structure of an RPG type inventory system in Godot 4.

=== Intro / Setup ===
0:00 Intro
0:45 Project Setup

=== Resource Data Structure ===
2:50 Item Data Resource
4:27 Slo...

▶ Play video
#

@muted fiber it's here

tall horizon
#

watch a bit farther. it fixes it

neon dagger
#

oh okay

#

not for me it didn't

#

he compiles right after this and it's got an error for me

tall horizon
neon dagger
#

my indents were messed up

#

but yeah, it crashed when I dragged the two slots together for some reason

tall horizon
#

SlotData doesn't have item. did you miss type it?

#

in SlotData

#

and why do all those lines end with \?

neon dagger
#

I don't know, I was copying the video

tall horizon
#

apparently that tells it that the boolean expresion continues on the next line. I didn't know that was a thing

neon dagger
#

line 5 or line 10?

#

oh line 5 isn't visible

tall horizon
#

you are looking for a property called item on a SlotData on line 11. try using itemdata

neon dagger
#

huh, that works

#

thanks

#

maybe I mistyped it

tall horizon
#

whoever made this tutorial needs to stop using lower extruder case for properties

neon dagger
tall horizon
#

lowerextrudercaselookslikethis

#

snake_case_is_this

#

andThisIsCamelCase

#

snake case is standard for properties in godot. I have no idea why the tutorial author thought lower extruder was a good idea. it's basically unreadable

neon dagger
#

stuck again, the inventory won't give control of the mouse back

#

so i can click the chest I made

#

the inventory uses a keypress to interact with the chest but my game is 2d and mouse controlled

narrow locust
neon dagger
#

I'm getting help with it

#

the canvaslayer was blocking it