0

I'm trying to match users inputted numbers to match an array(winning numbers) for a lottery game but I'm getting errors : How can I solve this?

"undeclared identifier"

uint8[] public numbers; // all numbers being stored in this array

mapping (uint8 => address payable[]) playersByNumber;

Function of setting the winning number.

function setWinNum(uint8 num1,uint8 num2,uint8 num3,uint8 num4,uint8 num5) public onlyOwner returns (uint8[5] memory ){

           uint8[5] memory numsFixed = [num1, num2,num3,num4,num5];
           //  selectedNumber = num; // this works for single number.
           
   return numsFixed;

   }

Function to assign winning numbers.

function determineWinner() public {
        require(msg.sender == owner);
        require(state == LotteryState.SecondRound, "Admin please set to second round");
        state = LotteryState.Finished;

     uint8[5] memory winningNumbers = setWinNum(numsFixed); -- says undeclared identifier
    
   // uint8 winningNumber = setWinNum(selectedNumber); works for single number.
   


         officialWinner(winningNumbers[]);

     selfdestruct(owner);
    }

Function to distribute winnings

function officialWinner(uint8 winningNumber) private returns ( uint256 ) {
               uint winnerCount = playersByNumber[winningNumber].length;
               
         //           require(winnerCount == 1);

         if (winnerCount < 0){
           ab;
         }

// so if theres winners distribute the money
         if (winnerCount > 0) {

             uint256 balanceToDistribute = address(this).balance/(2*winnerCount);// this gets the contract balance , divide 2 becase its only giving half the bal. w/ the haf balnce x winners

                 for (uint i = 0; i<winnerCount; i++) {
                     require(i==0);
            playersByNumber[winningNumber][i].transfer(balanceToDistribute);
           lotteryHistory[lotteryId] =  playersByNumber[winningNumber][i];
         
           address winner =  playersByNumber[winningNumber][i]; 
             lastWinner = winner;
             lastWinningAmount[winner] = balanceToDistribute;
              lastWinnerAmount=  lastWinningAmount[winner];  
       
           } 

1 Answer 1

0

Your are calling 'setWinNum(numsFixed)' inside of determineWinner(), but in this context, 'numsFixed' doesn't exist, you haven't declared it anywhere.

So the compiler tells you it's an 'undeclared identifier'.

7
  • thanks for responding, I put numsFxed as an arguement in the setWinNum function e.g (uint8[] memory numsFixed) but i get ''Wrong argument count for function call: 1 arguments given but expected 5''. & Invalid type for argument in function call. Invalid implicit conversion from uint8[5] memory to uint8 requested @olivierd
    – DeeGold
    Commented Nov 15, 2022 at 0:18
  • Because setWinNum is expecting five uint8 as arguments, and you are passing one array of size 5 of uint8. I think you are doing something weird here. What are you trying to accomplish with setWinNum()? Commented Nov 15, 2022 at 0:36
  • I'm trying match to the users 5 numbers (numbers that they pick) to match setWinNum numbers (admin sets the numbers). @OlivierD
    – DeeGold
    Commented Nov 15, 2022 at 1:50
  • But if the admin set the numbers, that means the number are kept on the smart contract, which means anybody can go read them and see the winning numbers. No data is private on a smart contract, everything is readable Commented Nov 15, 2022 at 2:12
  • yes that's true , later I'll use Chainlink VRF or Hashing. But for now I'm manually testing. @OlivierD
    – DeeGold
    Commented Nov 15, 2022 at 4:46

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.