#how would i make two items from the same resource script do two different things

21 messages · Page 1 of 1 (latest)

waxen parcel
#

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?

woven sable
#

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.

waxen parcel
#

very basic stuff right now

woven sable
#

okay yeah makes sense.

waxen parcel
#

so should i just make new classes for different item types?

woven sable
#

so you would click the item in the inventory to use or consume it? or something like that?

waxen parcel
#

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

woven sable
#

ahhh ok yes that sounds fun. But i see the issue then.

woven sable
#

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.

#

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.

waxen parcel
#

ill look it over. its going to be a long night lol

woven sable
#

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

waxen parcel
#

okay yeah, this looks really interesting

waxen parcel
#

im cooking something here... to be fair, that something is comparable to british gruel, but it should work for what im wanting to do

waxen parcel
#

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

woven sable
#

that sounds a little janky buuuut if it worked then it worked!

#

It honestly does make sense in like a common sense kind of way. Each item would have a different thing that is does (a function). So that sounds like a function as a variable.