Variables on other cogs?
rapscaLLion
Posts: 75
Hi there,
Suppose I have "Main Program" for example, and it calls "Sub Program" as an object during starttup.
Sub Program immediately initialized it's method "Method" in a new cog. Is there any way from "Method"
running on the other cog to access read and write variables in the Main Programand vice versa?
I have tried using the "@" symbol in various ways, no dice.
If not, any good way to pass these values back and forth with ease?
Thanks!
Suppose I have "Main Program" for example, and it calls "Sub Program" as an object during starttup.
Sub Program immediately initialized it's method "Method" in a new cog. Is there any way from "Method"
running on the other cog to access read and write variables in the Main Programand vice versa?
I have tried using the "@" symbol in various ways, no dice.
If not, any good way to pass these values back and forth with ease?
Thanks!
Comments
VAR
byte MyGlobalVar
All cogs can access global variables.
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"
Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
As RoboGeek mentioned, all subroutines (methods) in an object have access to the other subroutines, DAT labels, and VAR variables (and CON constants) in the object. One object has access to the named constants and public methods in any subsidiary object defined in its OBJ section(s).
Basically, you pass the address of any shared globals in the main program to a method in object b. If these are part of the initial environment for the separate cog, these addresses can be passed as a parameter to the start routine for the cog which calls COGNEW with a call to some Spin method with some parameters, one or more of which are these addresses. This might look like: