C
C#12mo ago
Zee

❔ is there a way for a method to have interchangeable parameter?

is there a way for a method to have interchangeable parameter depending on when I call it? so I have this method
public void DrankHealthBoost(Health_Boost potion)
{
health += 1;
}
public void DrankHealthBoost(Health_Boost potion)
{
health += 1;
}
this method has a parameter of type Health_Boost and when I call it I do this
private void CollectHealthPot(Health_Boost potion, Player pl)
{
pl.DrankHealthBoost(potion);

}
private void CollectHealthPot(Health_Boost potion, Player pl)
{
pl.DrankHealthBoost(potion);

}
is there a way I can change the DrankHealthBoost(Health_Boost potion) parameter so I can do something like this
private void CollectHealthPot(Shop potion, Player pl)
{
pl.DrankHealthBoost(potion);

}
private void CollectHealthPot(Shop potion, Player pl)
{
pl.DrankHealthBoost(potion);

}
so have the parameter to be of type class shop
12 Replies
phaseshift
phaseshift12mo ago
is there a way I can change the DrankHealthBoost(Health_Boost potion) parameter so I can do something like this
I dont get it
Thinker
Thinker12mo ago
How can you drink a shop? Jokes aside, yes, if what you want is for HealthBoost and Shop to have some common behavior, then what you are looking for is interfaces.
Zee
Zee12mo ago
ill change the names to something more suitable because originally you could only increase your health by DRINKING a potion but now you can get it as a random drop thought it was a dictionary but thx
SinFluxx
SinFluxx12mo ago
Get the potion as a random drop?
Zee
Zee12mo ago
yes like you go to the shop with money and then you get a random number depending on the number your given a random potion
SinFluxx
SinFluxx12mo ago
Wouldn't it still be the same type you pass through then?
Zee
Zee12mo ago
erm no because the purpose of the first parameter is to make the object the player interacted with go away so either the shop or the health potion depending on how they get it
SinFluxx
SinFluxx12mo ago
May be confusing naming then calling them both potion?
Zee
Zee12mo ago
yh will change that
phaseshift
phaseshift12mo ago
at the end of the day, the player still drinks the potion. Don't know why you're trying to tie the player to drinking a shop
SinFluxx
SinFluxx12mo ago
Yeah would have thought that should be dealt with separately
Accord
Accord12mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts