there are too many "on start of layout" I've seen many issues because of this.
you start..and reset the global variable, i take it these are buttons, so depending on what they click on.. they do X. put all those together. click a..go here. b do this, c
so.. on tap of OBJECT...add appropriate ACTION.
with each layout..they must use the main one. check that. hope it helps man..gl