Moving parented objects

I have created two objects using script.

Object B is parented to object A. The code is something like:

myObjectB.parent = myObjectA
myObjectB.location.x = myObjectA.location.x + myvar

The idea is to put the Object B in a position relative to Object A defined by the value of myvar.

The problem is that if I create the ObjectA in origin (0,0,0), the Object B is positioned in the right place, but if I put the cursor in any position different of (0,0,0) and create Object A, and then create the Object B, the Object B is moved away, not in the same relative position to Object A.

I know that is related to Global and Local coordinates, but I have no idea how to solve it.

Any idea.

I have solved…the problem was that the position was relative to parent, so the ObjectA.location must not be used.