0

thats my code:

 // SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol"; 
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/access/Ownable.sol";

contract CryptoYanush is ERC721, Ownable {
  constructor(string memory _name, string memory _symbol)
    ERC721(_name, _symbol)
  {}

  uint256 COUNTER;

  uint256 fee = 0.01 ether;

  struct Yanush {
    string name;
    uint256 id;
    uint256 dna;
    uint8 level;
    uint8 haste;
    uint8 health;
    uint8 manna;
    uint8 rarity;
  }

  Yanush[] public yanushe;

  event NewYanush(address indexed owner, uint256 id, uint256 dna);

  // Helpers
  function _createRandomNum(uint256 _mod) internal view returns (uint256) {
    uint256 randomNum = uint256(
      keccak256(abi.encodePacked(block.timestamp, msg.sender))
    );
    return randomNum % _mod;
  }

  function updateFee(uint256 _fee) external onlyOwner {
    fee = _fee;
  }

  function withdraw() external payable onlyOwner {
    address payable _owner = payable(owner());
    _owner.transfer(address(this).balance);
  }

  // Creation
  function _createYanush(string memory _name) internal {
    uint8 randHaste = uint8(_createRandomNum(50));
    uint8 randHealth = uint8(_createRandomNum(100));
    uint8 randManna = uint8(_createRandomNum(100));
    uint8 randRarity = uint8(_createRandomNum(100));
    uint256 randDna = _createRandomNum(10**16);
    Yanush memory newYanush = Yanush (_name, COUNTER, randDna, 1, randHaste, randHealth, randManna, Rarity);
    yanushe.push(newYanush);
    _safeMint(msg.sender, COUNTER);
    emit NewYanush(msg.sender, COUNTER, randDna);
    COUNTER++;
  }

  function createRandomYanush(string memory _name) public payable {
    require(msg.value >= fee);
    _createYanush(_name);
  }

  // Getters
  function getYanushe() public view returns (Yanush[] memory) {
    return yanushe;
  }

  function getOwnerYanushe(address _owner) public view returns (Yanush[] memory) {
    Yanush[] memory result = new Yanush[](balanceOf(_owner));
    uint256 counter = 0;
    for (uint256 i = 0; i < yanushe.length; i++) {
      if (ownerOf(i) == _owner) {
        result[counter] = yanushe[i];
        counter++;
      }
    }
    return result;
  }

  // Actions
  function levelUp(uint256 _yanushId) public {
    require(ownerOf(_yanushId) == msg.sender);
    Yanush storage yanush = yanushe[_yanushId];
    yanush.level++;
  }
}

when trying to compile get error at line 56 with undeclared. How to resolve this? remix-view

1 Answer 1

1

It's because you wrote 'Rarity' instead of 'randRarity' when you instantiate your struct line 56.

Hope this helps!

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.