Propeller and shared variables
danthony
Posts: 45
Does anyone know how to reference a variable outside of the top object from within the top object?
For instance if you had a main object and wanted to get the value from a variable in a child object of that main parent.
Thanks in advance for any help
For instance if you had a main object and wanted to get the value from a variable in a child object of that main parent.
Thanks in advance for any help
Comments
PUB GetX
return x
John Abshier
variables from the VAR-section are only direct accessible from INSIDE that object.
let's say you have a Topobject
MyTopObect.spin
inside the file MyTopObect.spin you have declared another object in the OBJ-section
inside the file MyChildObject.SPIN you have a variable in the var-section
and you want to READ this variable in the file MyTopObect.spin
for this you have to define a method inside the MyChildObject.SPIN
now you can READ the value of variable MyX inside the MyTopObect.spin
by coding
if you want to WRITE into variable MyX you have to define a method inside the MyChildObject.SPIN
and use it inside the the MyTopObect.spin
which wil stor evalue "123" into variable MyX
The names of the variables, objects and methods are free to choose
within the limitations of names in SPIN in general start with letter (and not a digit etc.)
best regards
Stefan