question

SudheerReddy avatar image
0 Likes"
SudheerReddy asked Matthew Gillespie commented

token.label?

In the below code ? is used. ? is going to say whether label exists on the token or not. If label exists the expression works. Here my doubt is if label is not there what the expression is going to return

level = current.TotalSupplied? - current.TotalDemanded?

if (itemDependentDemand)
	level = current.TotalSupplied? - current.TotalDemanded?;
else level = current.TotalSupplied? - (getinput(current) / getprocessflowvar(processFlow, "DepletionUnit", current.MainToken?));
FlexSim 20.0.0
if loop
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

·
Matthew Gillespie avatar image
3 Likes"
Matthew Gillespie answered Matthew Gillespie commented

Without the question mark that code will throw an exception if the object doesn’t have a label with that label name. With the question mark it will return nullvar instead.

· 2
5 |100000

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

SudheerReddy avatar image SudheerReddy commented ·

@Matthew Gillespie Thanks for feedback.

In your answer in the last sentence you specified as With the question mark it will return bulk car instead. What do you mean by bulk car here.

The other question is

Without question mark if it is throwing exception what is the advantage of using question mark in the above code. If the label doesn't exist then With or Without question mark if it throws exception, what is the advantage of having question mark


0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ SudheerReddy commented ·

That was an autocomplete typo, it should have said nullvar. You can read more about the ? operator here: https://docs.flexsim.com/en/20.0/Reference/CodingInFlexSim/FlexScriptAPIReference/Tree/treenode.html#Property-labelProperties

Using the ? is supposed to keep the code from throwing an exception if the label isn't there. Where is this code from?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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