Contract-Debugging

TypeError:使用結構時找不到成員或不可見成員

  • October 25, 2017

我正在為契約編寫程式碼以跟踪戲劇。我在這一行收到此錯誤:

play1.PlayTitle   = PlayTitle; (line 62 below)

browser/teste.sol:62:13: TypeError: Member “PlayTitle” not found or not visible after argument-dependent lookup in struct Plays.PlayActionInfo storage ref

$$ $$儲存參考 play1.PlayTitle = PlayTitle;

        ^-------------^

我確實在兩個結構中都定義了 PlayTitle。我設想使用者將在契約創建時以及播放資訊更新時輸入播放標題。我定義它兩次的事實可能是問題的一部分。

但是當我刪除包含 PlayTitle 的行時,下一行( play1.PlayWorkerName

$$ numUpdates $$ = 遊戲工作者名稱;) 得到錯誤。 有人可以解釋錯誤的含義嗎?任何其他程式碼建議將不勝感激。

我確實看到了具有相同錯誤的其他問題,但解決方案似乎與我的程式碼無關。

對於我的環境配置,我在 Chrome 瀏覽器中使用 Remix。

這是我的所有程式碼:

pragma solidity ^0.4.18;

contract Plays
{
   //used to store information about the owner of the Play
   struct TopLevelPlayInfo {
     address PlayOwnerAddress;
     bytes32 PlayOwnerName;
     bytes32 PlayTitle;
   }
//instance of the owner
TopLevelPlayInfo playi;

//map into the PlayOwner based upon the owner's address
mapping (address => TopLevelPlayInfo) public theTopLevelPlayInfo;

//used to store actions taken to complete Play
struct PlayActionInfo  {
 bytes32   PlayTitle;       
 bytes32   PlayWorkerName;
 address   PlayWorkerAddress;
 bytes32   PlayAction;
 bytes32   PlayActionDescription;
 uint256   PlayActionTimestamp;
 bytes32   PlayStatus;
}
//the instance of the struct
PlayActionInfo [] play1;

//map into the Play action
mapping (uint => PlayActionInfo) public thePlayActionInfo;

//State variables for storage - do I need these  
// as state variables since they are also in a struct? 
uint    numUpdates;
address theOwnerAddress;

//will be used to ensure only owner closes Play when work is accepted
modifier onlyOwner(){
 if(msg.sender != theOwnerAddress) revert();
 _;
}

//constructor for contract
function Plays(bytes32 thisPlayOwnerName, bytes32 thisPlayTitle) public  {
   //establish the owner
   playi.PlayOwnerAddress = msg.sender;
   theOwnerAddress        = msg.sender;
   playi.PlayOwnerName    = thisPlayOwnerName;
   playi.PlayTitle        = thisPlayTitle;
}

//used to enter a new action against thePlay
function PlayUpdate(
     bytes32   PlayTitle,
     bytes32   PlayWorkerName,
     bytes32   PlayAction,
     bytes32   PlayActionDescription,
     bytes32   PlayStatus)
     public {
       play1.PlayTitle                          = PlayTitle;
       play1.PlayWorkerName[numUpdates]         = PlayWorkerName;
       play1.PlayWorkerAddress[numUpdates]      = msg.sender;
       play1.PlayAction[numUpdates]             = PlayAction;
       play1.PlayActionDescription[numUpdates]  = PlayActionDescription;
       play1.PlayActionTimestamp[numUpdates]    = block.timestamp;
       play1.PlayStatus[numUpdates]             = PlayStatus;

       //update the number of updates to this contract
       numUpdates++;
}
}

謝謝

它看起來像是與適當的資料結構的鬥爭,所以我將其簡化為一個簡單的解釋。很多提示。

pragma solidity ^0.4.18;

contract Play {

   address public playOwnerAddress;
   bytes32 public playOwnerName;
   bytes32 public playTitle;

   // actions taken to complete Play

   struct PlayActionStruct  {
       bytes32   playTitle;       
       bytes32   playWorkerName;
       address   playWorkerAddress;
       bytes32   playAction;
       bytes32   playActionDescription;
       bytes32   playStatus;
   }

   // append-only list of actions

   PlayActionStruct [] public playActions;

   event LogInsertPlayAction(
       bytes32   _playTitle,
       bytes32   _playWorkerName,
       bytes32   _playAction,
       bytes32   _playActionDescription,
       bytes32   _playStatus);

   modifier onlyOwner(){
       require(msg.sender == playOwnerAddress);
       _;
   }

   function Play(bytes32 thisPlayOwnerName, bytes32 thisPlayTitle) public  {
       playOwnerAddress = msg.sender;
       playOwnerName    = thisPlayOwnerName;
       playTitle        = thisPlayTitle;
   }

   function appendPlayAction(
       bytes32   _playTitle,
       bytes32   _playWorkerName,
       bytes32   _playAction,
       bytes32   _playActionDescription,
       bytes32   _playStatus)
       public
       onlyOwner // restricts to contract deployer
       returns(bool success)
   {
       // Consider adding a series of require() guards here to validate inputs

       PlayActionStruct memory p;
       p.playAction            = _playTitle;
       p.playWorkerName        = _playWorkerName;
       p.playWorkerName        = _playWorkerName;
       p.playWorkerAddress     = msg.sender;
       p.playAction            = _playAction;
       p.playActionDescription = _playActionDescription;
       p.playStatus            = _playStatus;
       playActions.push(p);

       LogInsertPlayAction(
           _playTitle,
           _playWorkerName,
           _playAction,
           _playActionDescription,
           _playStatus);
       return true;
   }

   function getActionCount() public view returns(uint count) {
       return playActions.length;
   }
}

做事的方法總是不止一種,所以這可能會給你一些想法:Solidity 是否有很好解決且簡單的儲存模式?

希望能幫助到你。

引用自:https://ethereum.stackexchange.com/questions/29199