How to define global variables?

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Creater0822
Posts: 5
Joined: Thursday 19 November, 2020 - 21:31

How to define global variables?

Post by Creater0822 »

Presumably a rookie question, but as suggested by the subject:
Where in Enterprise Dynamics can I possibly define global variables to be read from by all Atoms in my model?

More specific on what I want to accomplish, is for example a textbox on which I could simply type a value, to become readable by other Atoms. So for example I would have a Source Atom, in which I have the global variable set as inter-arrival time in seconds. And then a textbox on which I can simply type 10 to have my Source Atom's inter-arrival time be 10s.
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: How to define global variables?

Post by HarryBunnik »

Hi Creator0822,

You can define global variables using Dimand local variables using Var.

So in code that would be something like:

Code: Select all

Do(
  Dim([valinterArrivalTime], vbValue, 10), 
  
  ....
)
And I would locate them on an initialize atom (Library => Tools => Initialize). That way you can be sure that it is always updated at the beginning of your simulation run. This is then the central point in your model where you can keep control over all your global variables (and labels and other things).

Another option is that you store such variables that must be updatable in table (with alias) and then read out the data on the initialize atom from the table:

Do(
Dim([valinterArrivalTime], vbValue, Cell(1, 1, refAliasOfyourTable),

....
)[/code]

Another option is that you read in the source directly from the table, but that has the downside that you need to update more when you are re-arranging the values stored in the table.

As you see, there are several ways to do things. I hope this helps you further!

Gr. Harry
Creater0822
Posts: 5
Joined: Thursday 19 November, 2020 - 21:31

Re: How to define global variables?

Post by Creater0822 »

Thanks a lot, that was a really quick reply!!
Post Reply