Ethereum calling a function doesn't take effect if I update two mappings

moatazsolimamoatazsolima Member Posts: 1
edited June 2016 in Solidity
This is Driving me crazy!! Please help asap.

I'm testing a very simple example
contract MyNewTest {

Student[] students;
mapping (string => uint) nametonumber;
mapping (uint => string) numbertoname;
uint counter;

struct Student
{
string name;
uint num;
}

function addStudent(string _name)
{
uint _id;
_id = students.length++;
students[_id].name = _name;
students[_id].num = _id;
numbertoname[_id] = _name;
nametonumber[_name] = _id;
}

function getLength() constant
returns (uint)
{
return students.length;
}

function getStudentNumber(string name) constant
returns (uint)
{
return nametonumber[name];
}

function getStudentName(uint number) constant
returns (string)
{
return numbertoname[number];
}

function getStudentAtPosition(uint x) constant
returns (string)
{
return students[x].name;
}

function getStudentNumberAtPosition(uint x) constant
returns (uint)
{
return students[x].num;
}
}
Am running a private local blockchain with mining turned on.

I tried to call

mynewtest.addStudent("Joe")

then mynewtest.getLength() it returns Zero although I added a new student.

However, inside the newStudent function if I remove either numbertoname[_id] = _name;

Or

nametonumber[_name] = _id;

everything works fine and when I add a student and do mynewtest.getLength() I get 1.

is there a constraint that I can't update two mappings in the same function? Does this code work for anybody?

Thanks
Post edited by o0ragman0o on

Comments

Sign In or Register to comment.