Share variables among Cscripts

To exchange variables between Cscripts blocks or have more inputs and outputs, the CVAR block is used.

Using the CVAR block global variables are defined that are accessible in all Cscript blocks in your simulation.

Use this block to:

  1. Send parameters to the Cscript blocks.
  2. Get numerical values from the Cscript block.
  3. Exchange numerical values between Cscript blocks
  4. Provide more inputs & outputs for the Cscript blocks.

Per global variable one CVAR is used. Define the name of the variable at the edit field "text1" of the block.

In the ANSI-C language both variables "a" and "A" can exist and have different values. In other words, "a" and "A" are not equal. At p1 in the properties you can also define the initial value. The declared variable can be used in all Cscript blocks in your simulation.

In the example below two global variables are declared: iVar1 and iVar2, both of the type integer. Their default value is set to


by defining the default value 1 at p1 for iVar1:

<br>Click to close the image

by defining the default value 2 at p1 for iVar2:

<br>Click to close the image

Both variables iVar1 and iVar2 are declared for all Cscripts in the simulation. In this simulation we will use the default value and replace it with a new value.

In the Cscript, the value of iVar1 and iVar2 is added and returned as the output of the Cscript block. The variables iVar1 and iVar2 get a new value being:


and thereby replacing the previous values. These new values are set at the outputs of the CVAR blocks.

The Cscript is shown below.

int y;

After running the simulation the output of the Cscript block becomes equal to 7 except for the first time step, where the output will equal the summation of the default values 1+2.

<br>Click to close the image

The outputs of the blocks CVAR are equal to 3 and 4, because of the assignment in line 5 and 6 in the Cscript.

© 2018 CASPOC, All rights reserved. Home   |   Terms and Conditions   |   Legal   |   Export Compliance   |   Privacy Policy   |   Site Map