C
C#5mo ago
Eren

✅ calling functions

im trying to test my functions but it keeps giving errors anyone that could help
37 Replies
Thinker
Thinker5mo ago
Send your $code
MODiX
MODiX5mo 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
Angius5mo ago
What function? What errors?
Eren
Eren5mo 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
Angius5mo ago
$code
MODiX
MODiX5mo 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
Angius5mo 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
Eren5mo ago
when i insert it it doesnt work
Angius
Angius5mo ago
How do you insert it? And describe "doesn't work"
Eren
Eren5mo ago
ill send u a ss
Eren
Eren5mo ago
No description
Angius
Angius5mo ago
Uh You're calling ItemSelection here Not MoveSelection And, as the error says, creating a new Pokemon also expects some data
Eren
Eren5mo ago
yeah wrong name my bad but still does the same stuff
Angius
Angius5mo ago
Takes different parameters though MoveSelection takes two, trainer and pokemon
Eren
Eren5mo ago
yeah
Angius
Angius5mo ago
ItemSelection takes one, whatever it is
Eren
Eren5mo ago
i just changed it to moveseletion that was a accident
Eren
Eren5mo ago
still gives me this
No description
Eren
Eren5mo ago
i have been trying for hours and i cant figure it out
Angius
Angius5mo ago
As the error says, creating a Pokemon requires some data
Eren
Eren5mo ago
like what
Angius
Angius5mo ago
Like what the error says
Eren
Eren5mo ago
do i have to give in all the data i made in the class in order for it to work
Angius
Angius5mo ago
No description
Angius
Angius5mo 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
Eren5mo ago
this is the constructor
No description
Angius
Angius5mo 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
Eren5mo ago
so do i now need to create everything required in the constructor in the main to test it
Angius
Angius5mo ago
Yes new Pokemon("Pikachu", ...etc)
Eren
Eren5mo ago
not like this ?
No description
Eren
Eren5mo ago
so something like this ?
No description
Eren
Eren5mo ago
now the one issue like u said is the function isnt static
Angius
Angius5mo ago
Yeah, so figure out what's the class that has this method And you will need an instance of it
Eren
Eren5mo ago
how do i figure that out i used the classes Trainer and pokemon in the function
Eren
Eren5mo ago
No description
Angius
Angius5mo 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 User5mo ago
Message Not Public
Sign In & Join Server To View