Multiple menu items point to 1 app using globals

I have a form app that has many functionalities.
I pass a global to the app from the menu to let the app know what the functionalities should be
This works fine until I open more than 1 menu item at a time

When i open menu item 1, it opens the app with the correct functionality based on the global

When i open menu item 2, it opens the app also with its correct functionality based on the global

however since they are both open at the same time, when I click back on the already open app with Global 1, it now has the functionality of the LAST app I opened, because the global has not changed.

I have options, but not great

  1. Dont allow more than 1 app open at a time.
  2. Inform the user to close the first app, however I dont know how to recognize. that it is open
  3. duplicate the code and create a copy of each app with its dedicated functionalities. This would be a hassle if I need to make changes

Anyone have ideas how to make this work?

Lew

It’s hard to visualize your exact scenario but I get similar things done with an additional global variable, aptly named [comingfrom], which could hold the last apps name or other. This gets updated with the last app the user opened and based on checking this, the next app visited knows how to modify behavior. This is like state-machine programming model.

Global variables have global scope also between apps.
If you have the same app called twice (once from menu item 1 and twice from menu item 2) all the globals set in the first call will be overloaded in the second call.
You should use local variable (in SC language called attributes) instead of global variables .

TY, I will give that a try… after I get my head around it :slight_smile:

But do I not need globals to pass the variable to the app from the menu?

Yes but you use a global var [MYVAR] just to pass the argument to the app and NOT to persist the state of the app between calls.
The state is persisted using an attribute {myattrribute}

In order to do so you first assign ,in a scriptInit event , [MYVAR] to {myattribute}.
Once done you can access/change {myattribute} only, completely forgetting the global var used only as an IN parameter for the sake of parameter passing.

Remember:

[myvar] is global everywhere. Inside the same app and across apps and also apps belonging to different projects!

Never use a global variable to persist the state of an app because if you have two apps (or two open instances of the same app as in your case) using [myvar], then one app is going to change the state of the other and you will get all sort of wierd behaviour.

Thank you, I will give this a try

I have a HUGE question on Globals
I think I have made a very basic error through my system, with regard to how I use globals

I am aware that global variable values are available to me within every function I run. However it was just pointed out to me that these values are shared ACROSS users. If so, and since I have not tested multi user, I may have a serious issue.

A. When I sign on a user, the user ID {user} is set to a variable
I then set that variable to a global [GLOBALuser] = {user}

In every app, I begin with {user} = [GLOBALuser] in order to update logs and display data on the screen.

So for example,
MENU “ {user} = lewis and also [GLOBALuser] = lewis.

In ever pp I run, I set {user} = [GLOBALuser] = lewis

This works fine in my single user environment

IF I had another user sign on, then it would set [GLOBALuser] = sharon.

Would not all MY updates then be using the sharon value???

How do I get around this.

B. there at=re times when running a PHP button, the code does not recognize a variable, say {varabc}
I get around this be seeing [GLOBALvarabc] = {varabc} in my main code and using [GLOBALvarabc] in the button code.
Again, another user might change this data if running the same app

C. When running a RUN Button, your tutorial suggests setting [I]=0; in scriptinit and incrementing it during the button code.
What happens when another user runs this, or any other app with that variable?

I must be missing something. I have 900 apps, I hope I do not have to revisit them all

Thanks all

@lewis200: You’ll have no problems, the “global” variables are global only to the logged in session. Other users will have their own copies of the global variables since their php session is different. This is a php feature not Scriptcase.