(Solved) Object picking problem

here’s the code i am using for item picking
I use one sprite with multiple animation with names and whenever i have to create an object for player i create the IDI sprite and change it’s animation according to the need but the problem is that if the IDI is created and the player is too close it picks the object before the animation change.
I hope i was able to explain

And what do you want to achieve? What is the goal?

the thing is that if the player picks the object before the animation is changed it adds nothing to the inventory i want to stop that

I don’t see any object creation in the code above. Also in that piece of code I don’t see any animation changes. So please provide complete related code.


Where is your condition about animation = “stone” to add to inventory?

step 1

step 2

step 3

Looks like condition with distance to IDI will run earlier then condition with collision.

So why you have these two separate conditions? I think you have to decide if you want logic to condition by distance or collision. Logicaly collision will not run becouse of condition with distance, where you are deleting object.

Is step 2 before step 3 because IDI is being deleted in step 2?

It is running though i mean whenever the IDI is close enough it will move toward it and when it is in collision it will get deleted

step 3 is an external even

When is step 3 executed? Before or after step 2?

it is before step 2. but if i set it after step 2 it doesn’t work

1 Like

It seems like it’s setting the animation twice. Once as a string by name but the 2nd one is getting the name as a number with which will fail if it’s not a number and set it to 0 and then it converts it to a string.

The actions are worded differently, I’m guessing one of them is from before GD syntax was changed.

Both are from few months ago before recent updates
so what should i do?

IDK if the 2nd one is needed if the 1st one does the same thing. If it is needed then it needs to be
GlobalVariableString(PickedItem) since PickedItem is a string. It’s currently GlobalVariable(PickedItem)

If you go into preferences, you can set it to highlight depreciated events. They don’t necessarily have to be updated but you can change them to the current syntax by editing them and picking the current version.

This is from an old project of mine

It is showing like this
and even if i delete the 2nd one it doesn’t change anything and i did changed what you said but then the inventory stopped working

I tried to recreate your project. It’s a basic concept. This works for me.
I like to use the link as a condition but that doesn’t change anything. And I use scene variables. I also moved the delete but again, that’s just my choice. IDK. It works. Are the object’s quantities greater than zero?

Try me, I added the drag behavior to the player, so just drag the stick figure.
Gold =1, Copper=2 and Bronze =5

My project (click the green [code] then [download zip]

It still needs some checks in case more than 1 item can be collected at a time.

Okay so i just changed it a little bit and it is working
and now it doesn’t needs step 2

1 Like