This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I was following a relatively simple YouTube tutorial (for making a inventory system) for a inventory prototype I'm working on, since I am sort of a novice with GDscript. All was going swimmingly until I tried the code. For the most part, everything works fine, I try to combine anything with "1" (for one material only). It may be important to note I am using a JSON file for my inventory categorization. Here is some of my code;

Here is my main inventory scenes code:

extends Node2D


var playing = false
var men_open = false
var holding_items = null

onready var inventory_slots = $Grid

const SlotClass = preload("res://scripts/player/")


func _ready():
    for inv_slot in inventory_slots.get_children():
        inv_slot.connect("gui_input", self, "slot_gui_input", [inv_slot])

func _input(_event):
    if Input.is_action_just_pressed("e_men"):
        if men_open == true:
            if playing == false:
                playing = true
                #get_tree().paused = false
                Global.is_paused = false
                men_open = false
        elif men_open == false:
            if playing == false:
                playing = true
                #get_tree().paused = true
                Global.is_paused = true
                men_open = true

    if holding_items:
        holding_items.global_position = get_global_mouse_position()

func slot_gui_input(event: InputEvent, slot: SlotClass):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT && event.pressed:
            if holding_items != null:
                if !slot.item: #put held item in slot
                    holding_items = null
                else: #swap the held item with the item in slot
                    if holding_items.item_name != slot.item.item_name:
                        var temp_item = slot.item
                        temp_item.global_position = event.global_position
                        holding_items = temp_item
                        var stack_size = int(JsonData.item_data[slot.item.item_name]["StackSize"])
                        var able_to_add = stack_size - slot.item.item_quantity
                        if able_to_add >= holding_items.item_quantity:
                            holding_items = null
            elif slot.item:
                holding_items = slot.item
                holding_items.global_position = get_global_mouse_position()

func int_inv():
    var slots = inventory_slots.get_children()
    for i in range(slots.size()):
        if PlayerInventory.inventory.has(i):
            slots[i].intialize_item(PlayerInventory.inventory[i][0], PlayerInventory.inventory[i])

func _on_fade_animation_finished(anim_name):
    playing = false
    if anim_name == "fadeout":

Here is my "Slot" Code
extends Panel


var default_tex = preload("res://sprites/inventory/tile_inv.png")
var empty_tex = preload("res://sprites/inventory/trans_tile.png")
var default_style: StyleBoxTexture = null
var empty_style: StyleBoxTexture = null

var item_class = preload("res://scenes/player/inv/Item.tscn")
var item = null


func _ready():
    default_style =
    empty_style =
    default_style.texture = default_tex
    empty_style.texture = empty_tex

    if randi() % 2 == 0:
        item = item_class.instance()

func refresh_style():
    if item == null:
        set('custom_styles/panel', empty_style)
        set('custom_styles/panel', default_style)

func take_away_slot():
    var inventory_node = find_parent("Inventory")
    item = null

func put_in_slot(new_item):
    item = new_item
    item.position = Vector2(0, 0)
    var inventory_node = find_parent("Inventory")

func intialize_item(item_name, item_quantity):
    if item == null:
        item = item_class.instance()
        item.set_item(item_name, item_quantity)
        item.set_item(item_name, item_quantity)

And here is what my JSON file contains:
{ "Titanium": { "ItemCategory": "Resource", "StackSize": 4, "Description": "Test A" -----}, "Gold": { "ItemCategory": "Resource", "StackSize": 4, "Description": "Test B" -----}, "Drill_D1": { "ItemCategory": "Tool", "StackSize": 1, "Description": "Test C" -----} }

Godot version Version 3.4.2 -- x64 Bit
in Engine by (12 points)

According to the error...

Somewhere in your code, you're trying to compare an int value with an Array, which doesn't make any sense (and, can't be done). So, something like this will trigger that error:

if 1 >= some_array: print('here')

However, I don't see the issue in any of the code you've posted...

I don't really want to read the whole code... try to specify an index for your array, because you can't compare int and array, obviously, you should compare one int with another int FROM the array

3 Answers

+1 vote

Console error always specifies which exact line of code was the reason of it.
Post only this line.

I bet You made a small syntax error when iterating entries of array in a loop. Like missed [] or ) and that made accidentally compare element of array with array itself.

by (8,188 points)
0 votes

Since the place in the code where there is a >= comparison is the line

if able_to_add >= holding_items.item_quantity:

then I suspect the issue is that somehow holding_items is getting assigned an instance of Item.tscn which somehow has item_quantity being an array. So maybe it's an issue in a script on Item.tscn, related to the item_quantity variable being an array when it's supposed to be an int.

by (180 points)
0 votes

probably here but idk
if abletoadd >= holdingitems.itemquantity:

by (71 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.