I have a problem with my code.
contract Registration {
address public owner;
uint conceptPrice;
uint conceptValue;
function Registration(uint _conceptPrice) public {
owner = msg.sender;
conceptPrice = _conceptPrice;
conceptValue = conceptPrice;
}
/////////////////////////////////////
/* Others code*/
/////////////////////////////////////
struct Request {
uint reqId;
uint amount;
uint percentage;
address modAdd;
//0 for pending, 1 accept, 2 decline
uint state;
}
//
Request[] public requests;
//mapping (uint => Request) requests;
function request(uint _amount, uint _percentage) public returns (uint numRequests) {
bool present = false;
for (uint i = 0; i <= participants.length; i++) {
if (participants[i] == msg.sender) {
present = true;
break;
}
}
//
if (msg.sender == owner || _amount < conceptPrice || _amount < balances[msg.sender] || _percentage > 5 || present == false) return;
Request memory req = Request({reqId : requests.length + 1, amount : _amount, percentage : _percentage, modAdd : msg.sender, state : 0});
//bissogna togliere i soldi a chi fa l'offerta
requests.push(req);
numRequests = requests.length;
}
uint[] ident;
uint[] per;
uint[] amountV;
function pendingRequest() public {
for (uint i = 0; i == requests.length; i++) {
if (requests[i].state == 0) {
ident.push(requests[i].reqId);
per.push(requests[i].percentage);
amountV.push(requests[i].amount);
}
}
}
function printReq() public constant returns (uint[] ident_){
ident_ = ident;
}
}
I created two different request (numRequests =2) but when i try to take value from array of object Request through the function pendingRequest i have an error: status 0x0 Transaction mined but execution failed. Array requests have values inside for example requests at position one is:requests[1] Why?
==is not correct. You need to check ifiis less thanrequests.length(<). That first code block was me just copying the incorrect part of your code. – Shawn Tabrizi Dec 09 '18 at 20:31requests– Shawn Tabrizi Dec 09 '18 at 22:00ident? – Shawn Tabrizi Dec 09 '18 at 23:12