Skip to main content
deleted 49 characters in body
Source Link
user19510
  • 28.1k
  • 2
  • 32
  • 49

The issue is that you can't push to arrays that are located in memory. (Such arrays are not resizable.)

A simpleOne possible fix is to just wait until you've putdo the structchanges in storage before trying to push to its array member:

function createBettingEvent(string _name, string _uid, uint _startTime, uint _endTime) public {
    bettingEvents.length += 1;
    bettingEvent memorystorage _bettingEvent;_bettingEvent = bettingEvents[bettingEvents.length - 1];
    _bettingEvent.name = _name;
    _bettingEvent.uid = _uid;
    _bettingEvent.startTime = _startTime;
    _bettingEvent.endTime = _endTime;
    bettingEvents.push(_bettingEvent);
    bettingEvents[bettingEvents.length - 1].bettors.push(Bettor(0, 0, 0, 0));
}

The issue is that you can't push to arrays that are located in memory. (Such arrays are not resizable.)

A simple fix is to just wait until you've put the struct in storage before trying to push to its array member:

function createBettingEvent(string _name, string _uid, uint _startTime, uint _endTime) public {
    bettingEvent memory _bettingEvent;
    _bettingEvent.name = _name;
    _bettingEvent.uid = _uid;
    _bettingEvent.startTime = _startTime;
    _bettingEvent.endTime = _endTime;
    bettingEvents.push(_bettingEvent);
    bettingEvents[bettingEvents.length - 1].bettors.push(Bettor(0, 0, 0, 0));
}

The issue is that you can't push to arrays that are located in memory. (Such arrays are not resizable.)

One possible fix is to just do the changes in storage:

function createBettingEvent(string _name, string _uid, uint _startTime, uint _endTime) public {
    bettingEvents.length += 1;
    bettingEvent storage _bettingEvent = bettingEvents[bettingEvents.length - 1];
    _bettingEvent.name = _name;
    _bettingEvent.uid = _uid;
    _bettingEvent.startTime = _startTime;
    _bettingEvent.endTime = _endTime;
    _bettingEvent.bettors.push(Bettor(0, 0, 0, 0));
}
Source Link
user19510
  • 28.1k
  • 2
  • 32
  • 49

The issue is that you can't push to arrays that are located in memory. (Such arrays are not resizable.)

A simple fix is to just wait until you've put the struct in storage before trying to push to its array member:

function createBettingEvent(string _name, string _uid, uint _startTime, uint _endTime) public {
    bettingEvent memory _bettingEvent;
    _bettingEvent.name = _name;
    _bettingEvent.uid = _uid;
    _bettingEvent.startTime = _startTime;
    _bettingEvent.endTime = _endTime;
    bettingEvents.push(_bettingEvent);
    bettingEvents[bettingEvents.length - 1].bettors.push(Bettor(0, 0, 0, 0));
}