1

I have to Contracts habibconcert and changer , there is a method for changing the tickets_number in "habib concert" , it works fine when working just with the contract itself but i want to access to to it in another Contract "changer" so I made an object of the "habibconcert" in Changer Class and try to use it in

   function changeTickets(uint new_tickets) returns(uint) {


      firstObject.tickets = new_tickets;

      uint updateTickets =  firstObject.tickets  = firstObject.tickets + new_tickets;
      return ( updateTickets);

        }

but i receive the these errors

          browser/habibconcert.sol:12:11: TypeError: Expression has to be an lvalue.
      firstObject.tickets = new_tickets;
      ^-----------------^


            browser/habibconcert.sol:12:33: TypeError: Type uint256 is not implicitly convertible to expected type function () view external returns (uint256).
      firstObject.tickets = new_tickets;
                            ^---------^ 

                       browser/habibconcert.sol:14:33: TypeError: Expression has to be an lvalue.
      uint updateTickets =  firstObject.tickets  = firstObject.tickets + new_tickets;
                            ^-----------------^

                                       browser/habibconcert.sol:14:56: TypeError: Operator + not compatible with types function () view external returns (uint256) and uint256
      uint updateTickets =  firstObject.tickets  = firstObject.tickets + new_tickets;
                                                   ^-------------------------------^                      

                           browser/habibconcert.sol:14:11: TypeError: Type function () view external returns (uint256) is not implicitly convertible to expected type uint256.
      uint updateTickets =  firstObject.tickets  = firstObject.tickets + new_tickets;
      ^----------------------------------------------------------------------------^

Thanks in advance my two Contracts here below as following

pragma solidity ^0.4.0;


contract changer{


   habibconcert firstObject =    habibconcert(0xdc544654fefd1a458eb24064a6c958b14e579154);

  function changeTickets(uint new_tickets) returns(uint) {


      firstObject.tickets = new_tickets;

      uint updateTickets =  firstObject.tickets  = firstObject.tickets + new_tickets;
      return ( updateTickets);

        }


}





contract habibconcert{

  uint  public tickets = 6;

  address owner_of_tickets;

  uint constant price = 1 ether;

   mapping(address=>uint) public purchasers;

  function habibconcert()payable{

        owner_of_tickets =  msg.sender;
  }


function  displayTickets_numbers()constant returns(uint){

    return tickets;


}

    modifier ownLycreature(){


        require(msg.sender ==  owner_of_tickets) ;

        //   && tickets == 0
        _;

        }



               function changeTickets_number (uint newtickets) ownLycreature{

                     tickets +=newtickets;

               }




function buytickets(uint amount)payable{

      if(msg.value!=(amount*price) || amount>tickets){

          throw;
      }

      purchasers[msg.sender] +=amount;

      tickets -=amount;


    // if(tickets == 0){

    //     //selfdestruct(owner_of_tickets);

    // }


}        


}
2

You cannot modify directly the attributes of another contract. You need to have setters, and then, you can change the values with these functions.

contract Called {
    uint public myuint;

    function set(uint _var) {
        myuint = _var;
    }

    function get() view returns (uint){
        return myuint;
    }
}

interface Called {
    function set(uint);
    function get() view returns (uint);
}

contract Caller {

    Called public called_address;

    function set_address(address _addy) {
        called_address = Called(_addy);
    }

    function set(uint256 _var) {
        called_address.set(_var);
    } 

}
| improve this answer | |
  • Hi Elisha Thank you very much for replaying great man, I just wan to say if I understand you right, you mean " when i wan to access to functions of a Contract from other Contract, I better define Interface and create setters or getters in it and in other Contract use the interface " correct man ,just please Explain about Interface where shoud we use it – jhonfkanadi2 jhonfkanadi2 Apr 1 '18 at 6:00
  • Just another Question what is function set_address(address _addy) { called_address = Called(_addy); } for? interface dose not have any constructor so why you have it – jhonfkanadi2 jhonfkanadi2 Apr 1 '18 at 6:46
  • You can't just do _addy.MyFunction(), it doesn't know how it works basically, you have to precise it. – Elisha Drion Apr 1 '18 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.