Variable in another object
Podion
Posts: 90
Hello
Can you tel me how to call a variable in another object?
I have declare a variable in VAR long keycode and I have to call this variable " keycode" in another object to print the value in a LCD screen and I don't make it.
Can you tel me how to call a variable in another object?
I have declare a variable in VAR long keycode and I have to call this variable " keycode" in another object to print the value in a LCD screen and I don't make it.
Comments
Andy
:
The first method is easy with single-element variables because you can substitute the object's method name where you want that variable. Again, I tend to use the second as this provides greater flexibility IMHO.
@Vega256
Im not sure about that.. but maybe the following code is going to answer your question.
I try the this code and I only get this symbol " ~ " on the LCD were it suppose to be the " keycode " any idea why ?
There is my main OBJ
And the LCD OBJ
You can not print the keycode with the str methode, it's not a string. If you want the code as decimal number use:
LCD.dec(IR.get_keycode)
But the other problem is that your keycode variable is continuosly polled in the Main methode, so you will see mostly the value -1. You can poll into a temporary variable and update the keycode variable only when a new vaild code is received. So you see always the last vaild number:
Andy
If it is -1 then the NEXT command is executed, and this restarts the repeat loop, so all the code after NEXT is not executed until keycode is no longer -1.
The ELSE in your code has no effect if you have the following LCD.str() command at the same indention level.
Remember also that here you execute the polling and the print in the same cog, so they are sequential, while in the previous code the Main methode is executed in another cog than the get_keycode and the print methodes. So writing to the keycode and reading the current value happens in two parallel cogs totally un-synchronized.
Andy