#How can I do something like this?

1 messages · Page 1 of 1 (latest)

fervent tapir
#

RemoveItem<ScriptObject_Weapon>(slot);
public void RemoveItem<T>(T type, int id)

I currently use a string to differentiate between different item classes, but I was wondering if there was another way to do this so I can future-proof, However, my idea of implementing this is producing an error. Any advice?

harsh remnant
#

if items have IDs, i don't see why you'd need this type in the first place though.

fervent tapir
harsh remnant
#

the ID could be unique per category regardless

#

either way you either need to supply a value for that T type parameter, or just remove it. Realistically if you don't need the generic that can be removed too

fervent tapir
#

I DID find a workaround, using typeof. Not EXACTLY what I wanted to do but it's much better than what I was doing before

harsh remnant
#

Can you show the implementation of RemoveItem

fervent tapir
#

@harsh remnant I can but currently I'm away from my computer and won't be back for a while.

I can at least tell you the inventory has different lists for different item types. This function is simply does an if/else statement to find the correct item type, and accompanying list, and then removing the 'slot' from the list

I could use an enum, but if I ever wanted to add more item types, Id have to add to the enum and all scripts thereof. Enums can also get messy that way, I've learned

harsh remnant