Which's the type of agent variable? How can I remove the type var (to remove the warning in my code). Please ignore the comments.

    uint nonce;
    struct Agent {
        uint idAgent;
        uint[] O_preferences;
    mapping(address => Agent) public agents;
    address[] public agentsInfo;
    /// @notice Crea un nuevo agente con sus parámetros
    /// @param _address dirección del agente 
    /// @param _idAgent id del agente
    /// @param _O_Preferences preferencias del agente
    function setAgent(address _address, uint _idAgent, uint[] _O_Preferences) public {
        var agent = agents[_address];
        agent.idAgent = _idAgent;
        agent.O_preferences = _O_Preferences;
        agentsInfo.push(_address) -1;

Last question: what does that -1 mean (on the last line)?

Thanks in advance!

1 Answer 1


The variable agent is a reference to an item from agents:

var agent = agents[_address];

Now agents is a mapping from address to Agent.

So you can replace var with Agent (with storage access)

Agent storage agent = agents[_address];

The -1 at the end of agentsInfo.push(_address) - 1 does nothing.

In old solidity version .push(..) returned the new array's length, so .push(..) - 1 is the position where the new item was stored.

In this particular case since the result is not assigned to anything it serves no purpose. If you remove - 1 it semanticly works the same.

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.