2014년 12월 9일 화요일

global variable not working in another screen

dear ai forum i am trying to make a quiz with app inventor 2 .So far it works perfectly but when i try to initialize a global  it appears only as local and as a result it doesnt work in other screens.. any help would be appreciated.thank you in advance 



Hi, You can pass the value with" OPEN ANOTER SCREEN WITH START  VALUE" or "CLOSE SCREEN WITH VALUE". In the new opened screen you can obtain the value with "GET PLAIN START TEXT".



Use Francesco's suggestion.     The words "global variable"  do not really mean GLOBAL.   Variables on a screen are only global within the screen.  With AI2, each screen acts as a separate application that can communicate with the other screens (if the developer provides the appropriate code).  Franacesco provide a very good way to share data between screens.  Another way is to use the TinyDB.   Simply, you put a TinyDB on EACH screen in your app that has to be able to use the "GLOBAL" values.  (So, global values are NOT really global at all, only usable in one screen unless declared on another).  If you need one of the values on a second screen, you retrieve it from the TinyDB using the tag under which you saved it in the original screen.

Either use Franacesco's method or a TinyDB.  Both work.


댓글 없음:

댓글 쓰기