question

Jay Khedekar avatar image
0 Likes"
Jay Khedekar asked Felix Möhlmann answered

How to use one code to increase all tracked variable based on a label name?

So, there's quite a few moving parts here.
I have a model which sets label. For instance,

I have a label called PartName which has PartName saved in it.

I then created tracked variable with exact same name as the label PartName.

I want to then increment the Tracked Variable by PartWeight label

All these labels are pulled from a list


Now I am trying to do this in FlexScript to increment my tracked variable for all label names using just one code block.

double initial = TrackedVariable(token.pulled[token.loopcount].PartName).value;
double val = token.pulled[token.loopcount].PartWeight.value;
TrackedVariable(token.pulled[token.loopcount].PartName).value = initial + val;


This isn't currently not incrementing the value of tracked variable. What am I doing wrong? Is there a better way to do it?




FlexSim 23.0.15
flexscripttracked variables
5 |100000

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

1 Answer

Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered

Remove the "value" in line 2. You are already accessing the value of the label.

object.labelName -> value of label "labelName"
object.labels["labelName"] -> node of label "labelName"
object.labels["labelName"].value -> value of node of label "labelName" == value of label "labelName"

For tracked variables, "TrackVariable(varName)" accesses the node, so there you always need the "value"

5 |100000

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