0

I am building an auction smart contract in Remix with random winners being picked. And I am not getting any value out of the following function:

 }
    function revealWinners() public {
        for (uint id = 0; id <3; id++) {
            Item storage currentItem=items[id];
            if(currentItem.itemTokens.length != 0) {
                uint randomIndex = (block.number /
                currentItem.itemTokens.length)% currentItem.itemTokens.length;
                uint winnerId = currentItem.itemTokens[randomIndex];


            }

Everything else is working as it should but I have been stuck on this for a while, anyone here have an idea what I am missing?

1 Answer 1

1

To fulfill your requirement may be returns may solve it.

  function revealWinners() public returns (uint) {
        for (uint id = 0; id <3; id++) {
            Item storage currentItem=items[id];
            if(currentItem.itemTokens.length != 0) {
                uint randomIndex = (block.number /
                currentItem.itemTokens.length)% currentItem.itemTokens.length;
                uint winnerId = currentItem.itemTokens[randomIndex];
                return winnerId;
        }
    }
 }

update:


If you want to return any value from the function then you have to use return keyword as other programming language do . As you see in the function

function revealWinners() public returns (uint){

you have to use returns(data_type_Or_datatype_with_name) in the function. so the function have to be like this:-

function functio_Name(agr1,agr2,..) returns (ret_arg1,ret_arg2,..){
//logic here
return(ret_arg1,ret_arg2,..)
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.