its something ive been thinking about for a while, and the more i think about it the more confused i get. I have a script that allows the creation of resources that i use as items. so for example i want to have an item that heals the player and one that idk gives them more strength or something. these are however two very different stat modifiers and so how would i put this data in the respective items? is there a way i could maybe embed a script into the resource?
#how would i make two items from the same resource script do two different things
21 messages · Page 1 of 1 (latest)
Hmmm. What data does your Item resource currently use (like what variables does each item have).
It seems like maybe Potions could be a more specific thing which would have a separate script or even a class defining what they do. They have an Item associated with them, but they would also be a Potion, and then more specifically a health potion. I feel like it really depends on how your game is structured, though.
okay yeah makes sense.
so should i just make new classes for different item types?
so you would click the item in the inventory to use or consume it? or something like that?
so its something far worse. i got that part figured out but you physically drag the inventory slot that represents the item onto the party member
but like i said, i got that part more or less figured out
ahhh ok yes that sounds fun. But i see the issue then.
in that case, I would probably put the use function (or whatever you want to call it) in a script for the health potion that extends the invItem. So that way it contains the info for what it should do, and it also has whatever data and functionality an item has.
Godot Forum
Godot Version Godot-4 Question I have made resources for items, inventory and inventory slots that are hold in an array. I have a working pick up and hotkeys for the slots, I managed to clear the slot when using the item but I’m having a hard time making the item influence player for example increasing his speed. What would be the best way to...
for example it seems like this person was trying to do basically the same thing.
the use(player) function takes a player as an argument so it will know which person to apply the effect to.
ill look it over. its going to be a long night lol
mm yeah, it's really just general suggestions. The specific code and everything depends on your game.
class_name SpeedPotion
extends Item
var magnitude: int
func _init(p_magnitude: int = 1) -> void:
magnitude = p_magnitude
func use(p_user: PlayerData) -> bool:
p_user.speed += magnitude
return true
this is really the only part that seems like what you might wanna do
okay yeah, this looks really interesting
im cooking something here... to be fair, that something is comparable to british gruel, but it should work for what im wanting to do
so what i ended up doing it a little janky. basically i created a variable within the resource that's a string value that points to a script which contains a function that applies the modifier. im not convinced my way is the best, but i think it'll do for now