I'm a total beginner with solidity, I've searched on google and here but unfortunately I have not found what I'm looking for.
So my problem is with the following lines :
pragma solidity ^0.8.0;
contract PsoukraceFactory {
struct Psoukrace {
string name;
string title;
uint level;
uint HP;
uint defence;
uint dodge;
uint luck;
uint intelligence;
uint strenghth;
uint attack;
uint speed;
}
Psoukrace [] public psoukraces;
function _createPsoukrace( string memory name, string memory title, uint level, uint HP, uint defence, uint dodge, uint luck, uint intelligence, uint strength, uint attack, uint speed) public view returns (string memory, uint) {
psoukraces.push(Psoukrace(name, title, level, HP, defence, dodge, luck, intelligence, strength, attack, speed));
return ("test1",
"test2",
1,
2,
3,
4,
5,
6,
7,
8,
9);
}
}
I get the following error :
Different number of arguments in return statement than in returns declaration. --> contracts/Psoukrace.sol:27:8:
I don't understand what happened as I have seen (maybe I'm wrong here) I have 11 variables as arguments ( 2 string + 9 uint ) same into my psoukraces array and into my Psoukrace struct
Any help will be appreciated, thank you in advance!
You have this return
statement
returns (string memory, uint)
this saying you are going to return 2 things: string and uint. However, in function, you are returning
return ("test1",
"test2",
1,
2,
3,
4,
5,
6,
7,
8,
9);
11 elements. you have to add each type into returns()
.
returns (string memory,string memory,uint,uint...9times)
after you fixed this you will get another error saying that "Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable". Becase your marked your function as view
which means that your function is not going to modify the state but you are actually modifying by pushing psoukraces.push()
. so you also have to remove the view
from the function.