VAR Suggestion
Dave Hein
Posts: 6,347
VAR variables are useful because it is easy to create multiple instances just by referencing an object multiple times in the OBJ section. However, this causes problems when the same object is referenced by other objects. This creates independent sets of variables when someone really wants to have one set. Newbies and Oldies run into this problem all the time when using objects like FullDuplexSerial.
My suggestion is to have a new object section that forces a single instance to be created unless an object is referenced multiple times within another object. I call the new object symbol SHR for shared. It would look something like this:
EDIT: I realize that SHR conflicts with the opcode for shift-right, but it's just an example. Some other symbol could be used instead of SHR.
My suggestion is to have a new object section that forces a single instance to be created unless an object is referenced multiple times within another object. I call the new object symbol SHR for shared. It would look something like this:
OBJ ser1 : "FullDuplexSerial" ' Private object -- just like the current way SHR ser2 : "FullDuplexSerial" ' Shared object -- other objects can share this oneAny object that declares FullDuplexSerial in the SHR section will use the same VAR space when it calls an FDS method. I think this would make Spin more useful and easier to use for newbies and oldies.
EDIT: I realize that SHR conflicts with the opcode for shift-right, but it's just an example. Some other symbol could be used instead of SHR.
Comments
I haven't thought about the implications of this solution. Could DAT-variables be a solution to that. Or are DAT-variables harder to handle?
keep the questions coming
best regards
Stefan
I think you are on the right track! I struggled for over a year with trying to figure out how to use a global variable with multiple objects. To me, the literature was very unclear as to how to declare a var that could be accessed by multiple objects. Thanks to jonnymac I can now use a VAR shared by multiple OBJ's.
Jim
@Jim, I would like to see a global section also where all objects could directly access global variables. That would be very useful.