How do I access another object's constants
william chan
Posts: 1,326
Usually I declare all the pins in the Main object.
Lets say
CON
redledpin = 12
After that if another object needs to know the pin number of the red led, what's the best way to do it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Lets say
CON
redledpin = 12
After that if another object needs to know the pin number of the red led, what's the best way to do it?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Comments
#redledpin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Toys are microcontroled.
Robots are microcontroled.
I am microcontroled.
If it's not Parallax then don't even bother. :-)
·
Mini-Din/PS2 connectors are for sale! 5 for $1! PM me if you wish to make an order.
Cheap·shipping unless specified!··········150 left!!··
You need to define your constants in a lower level object, then they can be referred to in some higher level object by using the obj#constant notation. There are ways to define an object without any instance variables, so you can declare multiple instances where needed and no unnecessary code or data is allocated. One example is DongleBasic from the Object Exchange. There are all sorts of important constants declared in BB_definitions.spin that are referenced in other objects and in the main object.
How would you ensure to that don't inadvertently reuse a already used pin?
Isn't it better to have all pins defined in the top object file?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
You could have the I/O pins all defined in the top object file as long as they're passed as parameters to the various start methods of the "lower" object files. I've done that in other programs. Both schemes are useful.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propalyzer: Propeller PC Logic Analyzer
http://forums.parallax.com/showthread.php?p=788230