question

Darwin S avatar image
0 Likes"
Darwin S asked Jeff Nordgren commented

How to Get Value of Global Variable with Array?

Hi

I'm trying to get the Value of Array From my Global Variable but the Script Always return Empty Array

Here is My Model

Added EDD_autosave.fsm

Here is the Code that i use (I used it in Object Accepted ) as Entry Trigger

I already declared the Global Variable like This

But it always Return Empty Array in the Code


Thank you

FlexSim 19.0.9
flexsim 19.0.9arrayscriptglobal variable
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeff Nordgren avatar image Jeff Nordgren commented ·

@darwin.s,

Your model need a little more that just setting the OrderArrayIndex to 1. In the attached model, int the OnEntry trigger of Accepted, I added code to show you the values that are in the variables you are trying to use. And nothing ever gets put into your OrderSize array... it's empty. So in the line:

int PcNeeded = OrderSize[order-1];

PcNeeded is always equal to 0. So the following "if" statement is never true so it never increments the OrderArrayIndex value.

Just run the attached model and when it stops, just go through the code by pressing the Next Line button at the top of the code. That will step you through the code and show you what is in your variables.

added-edd-JN1.fsm

1 Like 1 ·
added-edd-jn1.fsm (11.8 MiB)

1 Answer

tannerp avatar image
1 Like"
tannerp answered

@darwin.s,

Your model is trying to access the 0 index of the array, but it can't because in FlexSim, Arrays are 1-based. See the User Manual for more information.

I suggest setting the initial value of the "OrderArrayIndex" Global Variable to 1 instead of 0. Then the model should work just fine. I hope this helps!

added-edd-autosave_1.fsm


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.