Function call needs a number, object variable not working


I’m trying to make my own inventory proof of concept, and I’m trying to make it as robust as possible for a serious project I’d like to make

So, I have this item with different animations, one for each item, and an ID variable on it that changes the item it is

I want to have item collecting be a function call, so I made this simple function here:

But when I tried to optimize it this way, it gets an error:

I’m aware that I’m putting a string where a number should be, so I’m wondering, is there a way to make FoodID go in as the number it’s supposed to be instead of being read as a string? ToNumber didn’t work

And also, if I add items, would it be better to have each item as a separate object but in a group so I can add animations to the individual items?

(Note: I don’t have anything that displays the inventory yet, is there a way to see inventories in the debugger?)

Thanks in advance

Hi, I don’t have the answer to your questions and someone who knows better than me will probably respond soon. Just two things that immediately stick out:

  1. In your function you set the parameter ‘quantity’ which is a number to string. But for the repeat event you need a number, so there is no reason to use ToString there.

  2. You get an error in your event because the name of the object variable (FoodID) shouldn’t be in quotation marks, so it is just FoodItem.Variable(FoodID).

1 Like

Perhaps the issue is as simple as the quotes around your variable name? Honestly don’t work with funcs too much but from I can see those quotes shouldn’t be there.

FoodItem.Variable(FoodID) (without quotes)

I can’t believe it was that simple, the error is gone!
Thanks for pointing that out ^^

1 Like