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. | Twitter

+1 vote

Here is a video link to my problem that I have uploaded to youtube:

    if dropable:
    if Input.is_action_just_pressed("right_click"): 
        if inventory[dropable_index] != null: # If input and slot isnt empty add and remove 1
            if inventory[dropable_index].amount < inventory[dropable_index].max_amount:
                if hand_array[0].amount > 1:
                    inventory[dropable_index].amount += 1
                    hand_array[0].amount -= 1
            if hand_array[0].amount > 1:
                var saved = hand_array.duplicate(true) # A dup that SHOULDNT TOUCH THE ORIGNAL ARRAY
                saved[0].amount = 1 # sets it to one ONCE
                print(hand_array[0].amount) # GETS TOUCHED ANYWAY
                inventory[dropable_index] = saved[0] # Setting the new inventory slot to new item
                hand_array[0].amount -= 1 # Removes one to make it look like its dropping a item

for what ever reason this website cant format my code correctly...

anyways I am trying to duplicate an item in the array between two different arrays one being the inventory and one being the held item array but for what ever reason it keeps touching the held item array when I SPECIFICALLY TOLD IT, ITS A DUPLICATE and it still touches the array like its still referencing it when i told it, it shouldn't!

Godot version 3.3.2
in Engine by (161 points)

1 Answer

0 votes

I can't see any problem with your code. But I had an idea: maybe your handarray is referencing some object that is pending an update on the next frame? If that is a cause of the problem then calldeferred may be a solution. Calling the update code later.

by (202 points)

Actually figured it out with some help from Reddit, the issue is that the data stored is a custom class that doesn't get stored but referenced which is why this happens.

Thanks for the comment though!

Happy that you solved your problem :)

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.