1

I've just started learning solidity and I tried to make a contract in which you are able to add names to Santa's naughty or nice list, and I want to be able to enter a name and I want the output to be whether the name is on the naughty or nice list or doesn't exist. Here I just tried to see if the inputed name is in the Naughty list and it was giving me the error message: Undeclared Identifier. I get this error in the place highlighted in the last function, thank you to anyone that helps.

pragma solidity ^0.8.11;

contract SantaList {

    struct NaughtyList{
        string badBoy;
        uint position;
    }
    struct NiceList{
        string goodBoy;
        uint position;
    }

    NaughtyList[] public badNames;
    NiceList[] public goodNames;

    uint internal nextPosition = 1;

    function AddToBadList(string memory badBoy) public{
        badNames.push(NaughtyList(badBoy, nextPosition));
        nextPosition++;
    }

    function AddToNiceList(string memory goodBoy) public{
        goodNames.push(NiceList(goodBoy, nextPosition));
        nextPosition++;
    }

    function GetNaughtyList() view public returns(NaughtyList[] memory){
        return badNames;
    }

    function GetNiceList() view public returns(NiceList[] memory){
        return goodNames;
    }

    function CheckList(string memory name) public {
        for(uint i = 0; i < badNames.length; i++){
            if(badNames[i].badBoy == **badBoy**){
                return **badBoy**;
                return " is on the naughty list";
            }
        }
    }
    
}
1
  • 1
    Variables can only be public or private , not internal
    – Majd TL
    Commented Dec 27, 2021 at 17:15

1 Answer 1

0

If you want to check if there's a name in the badNames

function CheckList(string memory name) public view returns (string memory) {
    for(uint i = 0; i < badNames.length; i++){
        if(badNames[i].badBoy == name){
            return string(abi.encodePacked(name, " is on the naughty list"));
        }
    }
    return string(abi.encodePacked(name, " is not on the naughty list"));
}

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.