C
C#11mo ago
Eren

✅ calling functions

im trying to test my functions but it keeps giving errors anyone that could help
37 Replies
Thinker
Thinker11mo ago
Send your $code
MODiX
MODiX11mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Angius
Angius11mo ago
What function? What errors?
Eren
ErenOP11mo ago
so i wanna test this function in my main public int MoveSelection(Trainer trainer , Pokémon pokemon) { int index = -1 ; while (index == -1) { Console.WriteLine($"Trainer {trainer.Name}, whatr move would you like to do ?"); ItemOverview(); for (int i = 0; i < pokemon.Moves.Count; i++) { Console.WriteLine($"{i + 1} , {pokemon.Moves[i].Name} ({pokemon.Moves[i].PowerPoints} "); } if (int.TryParse(Console.ReadLine(), out int input)) { if (input >= 1 && input <= pokemon.Moves.Count) { if (pokemon.Moves[input - 1].PowerPoints > 0) { index = input - 1; } else { throw new Exception("Selected move does not have any remaining Power Points"); } } else { throw new Exception("Invalid move index given"); } } else {
throw new Exception("invalid input");

} } return index; } i dont know what parameters to give in
Angius
Angius11mo ago
$code
MODiX
MODiX11mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Angius
Angius11mo ago
And you give it the parameters that it needs It wants a Trainer and a Pokemon So you give it a Trainer and a Pokemon
Eren
ErenOP11mo ago
when i insert it it doesnt work
Angius
Angius11mo ago
How do you insert it? And describe "doesn't work"
Eren
ErenOP11mo ago
ill send u a ss
Eren
ErenOP11mo ago
No description
Angius
Angius11mo ago
Uh You're calling ItemSelection here Not MoveSelection And, as the error says, creating a new Pokemon also expects some data
Eren
ErenOP11mo ago
yeah wrong name my bad but still does the same stuff
Angius
Angius11mo ago
Takes different parameters though MoveSelection takes two, trainer and pokemon
Eren
ErenOP11mo ago
yeah
Angius
Angius11mo ago
ItemSelection takes one, whatever it is
Eren
ErenOP11mo ago
i just changed it to moveseletion that was a accident
Eren
ErenOP11mo ago
still gives me this
No description
Eren
ErenOP11mo ago
i have been trying for hours and i cant figure it out
Angius
Angius11mo ago
As the error says, creating a Pokemon requires some data
Eren
ErenOP11mo ago
like what
Angius
Angius11mo ago
Like what the error says
Eren
ErenOP11mo ago
do i have to give in all the data i made in the class in order for it to work
Angius
Angius11mo ago
No description
Angius
Angius11mo ago
Parameter name is required At least And there are other parameters it needs Look at what the constructor of Pokemon is, and what parameters it requires
Eren
ErenOP11mo ago
this is the constructor
No description
Angius
Angius11mo ago
As for the second error, MoveSelection is not static, it's an instance method So... it needs an instance Cool, now you know what's needed, then
Eren
ErenOP11mo ago
so do i now need to create everything required in the constructor in the main to test it
Angius
Angius11mo ago
Yes new Pokemon("Pikachu", ...etc)
Eren
ErenOP11mo ago
not like this ?
No description
Eren
ErenOP11mo ago
so something like this ?
No description
Eren
ErenOP11mo ago
now the one issue like u said is the function isnt static
Angius
Angius11mo ago
Yeah, so figure out what's the class that has this method And you will need an instance of it
Eren
ErenOP11mo ago
how do i figure that out i used the classes Trainer and pokemon in the function
Eren
ErenOP11mo ago
No description
Angius
Angius11mo ago
But what class is the method inside of? Program? Then you need an instance of Program Or, alternatively... make the method static
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server