C
C#11mo ago
Eren

functions

i wanna know how i can use functions created in different classes inside of a other class
13 Replies
Eren
ErenOP11mo ago
´´´cs public static string DoMove(int Index, Pokémon target,Pokémon user) { Move move = user.Moves[Index]; if (move is DamageMove ) { return ((DamageMove)move).DoDamage(user, target); } else if( move is HealingMove) { return ((HealingMove)move).DoHeal(user); }
return ""; ´´´ the functions i want to use in here are DoDamage and DoHeal
Angius
Angius11mo ago
Since the methods are static... ClassName.MethodName() If they aren't, then you need an instance
Eren
ErenOP11mo ago
thats how i call them ?
Angius
Angius11mo ago
No, you call both DoDamage() and DoHeal() on an instance of Move
Eren
ErenOP11mo ago
these functions are not static
Angius
Angius11mo ago
Are they both methods of the Move class?
Eren
ErenOP11mo ago
so i will need a instance
Angius
Angius11mo ago
Yeah And you have one, so everything looks fine What's the issue, then?
Eren
ErenOP11mo ago
i also need to be able to make this code - each time when this gets used how do i do that --PowerPoints?
Angius
Angius11mo ago
(as a side note, you can have a cast automatically with an is operator, so your current code:)
if (move is DamageMove )
{
return ((DamageMove)move).DoDamage(user, target);
}
if (move is DamageMove )
{
return ((DamageMove)move).DoDamage(user, target);
}
(can just be this:)
if (move is DamageMove dm )
{
return dm.DoDamage(user, target);
}
if (move is DamageMove dm )
{
return dm.DoDamage(user, target);
}
What do you mean "make this code each time when it gets used"? Make what code? And what do you mean by "make", "run"?
Eren
ErenOP11mo ago
i mean make it minus each time off of the powerpoints do i put in the the if and in the else if the statment --powerpoints?
Angius
Angius11mo ago
Sure, try it
Eren
ErenOP11mo ago
already did but because of the return statement it goes undetectable also if u need more context i can show u what i need to make if that helps u if u dont need it its fine just incase Short description A Pokémon can do both a damage move and a healing move. Implementation • Implement a function based on an index of a move and a Pokémon's information of the execution in text • First select the move that corresponds to the given index from the moves of the Pokémon • Do the DoDamage execution or DoHeal execution respectively, if the move is a damage or healingmove is • Then enter the number of times the move can be performed (PowerPoints) with a to downstairs • Also return the text of the move execution in both cases
Want results from more Discord servers?
Add your server