SOLIDITY:尝试着手 Mapping/Struct 给出 "player" 倍数 "tickets",数组有问题

SOLIDITY: Trying to get working Mapping/Struct for giving a "player" multiple "tickets", problem(s) with array

在此先感谢您来到这里并尝试查看我的错误代码。

所以,我在尝试向人们“出售”门票并让他们有可能购买 >=1 时遇到了一些麻烦。

现在的问题是,我无法将 6 个数字的数组与机票相关联。

怎么了?谢谢!

//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract Lottery is Ownable {
    
   uint256 constant ticketprice = 1 ether;
   address  pool = addresshere;
   uint ID = 0;
   uint256 startinglottery;
   
   struct Picket { 
   uint ID;
   uint[6] ticket;
   }
   
   mapping (address => Picket) hope;
   address[] players;
   
    constructor() {
    startinglottery = 0;
    }
    
    
    function StartLottery() public onlyOwner {
    startinglottery = 1;  
    }
    
    function EndLottery() public onlyOwner {
        
    startinglottery = 0;
    }
    
    function BuyTicket(address _address) public payable {
        //check
        require(msg.value >= ticketprice, "not enought money!");
        require(startinglottery == 1, "lottery isn't started.");
        //pay
        payable(pool).transfer(msg.value);
        //do stuff
        Picket memory picket = hope[_address];
        picket.ID = ID;
        picket.ticket = [1,2,3,4,5]; //should be random with chainlink, but trying to understand the basic one.
        players.push(_address);
        ID++;
        
    }
    
    function getTicket(address _address) public view returns(uint, uint[6] memory) {
        return (hope[_address].ID, hope[_address].ticket);
    }

    
}
picket.ticket = [1,2,3,4,5];

您在此尝试将 5 项数组分配给 6 项数组。您需要明确定义第 6 个值 - 这是 0.

的默认值

此外,由于您传递的是硬编码的低值,编译器错误地将它们标记为 uint8。您至少需要将第一个转换为 uint256(或其别名 uint),以便编译器识别正确的数据类型。

picket.ticket = [uint256(1), 2, 3, 4, 5, 0];