✅ calling functions
im trying to test my functions but it keeps giving errors anyone that could help
37 Replies
Send your $code
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/What function? What errors?
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
throw new Exception("invalid input");
} } return index; } i dont know what parameters to give in
$code
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/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
when i insert it it doesnt work
How do you insert it?
And describe "doesn't work"
ill send u a ss
Uh
You're calling
ItemSelection
here
Not MoveSelection
And, as the error says, creating a new Pokemon
also expects some datayeah wrong name my bad but still
does the same stuff
Takes different parameters though
MoveSelection
takes two, trainer and pokemonyeah
ItemSelection
takes one, whatever it isi just changed it to moveseletion
that was a accident
still gives me this
i have been trying for hours and i cant figure it out
As the error says, creating a
Pokemon
requires some datalike what
Like what the error says
do i have to give in all the data i made
in the class
in order for it to work
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 requiresthis is the constructor
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, thenso do i now need
to create everything required in the constructor
in the main to test it
Yes
new Pokemon("Pikachu", ...etc)
not like this ?
so something like this ?
now the one issue like u said is the function isnt static
Yeah, so figure out what's the class that has this method
And you will need an instance of it
how do i figure that out
i used the classes Trainer and pokemon in the function
But what class is the method inside of?
Program
?
Then you need an instance of Program
Or, alternatively... make the method staticUnknown User•11mo ago
Message Not Public
Sign In & Join Server To View