question

Jouky D avatar image
0 Likes"
Jouky D asked Jouky D commented

How to know the classtype in flexscript?

Hello everyone,

I am trying to know if a input value of a function is an Object or an integer. I found these two commands, however they are only useful on Objects or Treenodes: isclasstype and dataType. Is there a way to know if a value is an integer or an object? Also, is there a way to make "iferror" in flexscript?

Thank you!

FlexSim 23.1.2
flexscriptdata typeclasstype
· 3
5 |100000

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

Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

For those finding this post while searching for classtype information:

For known objects you match isClassType() using the macros for the class types eg:

isclasstype(current,CLASSTYPE_FIXEDRESOURCE)

You can also find the class object and test that:

classobject(current).name=="Processor"
0 Likes 0 ·
Julie Weller avatar image Julie Weller commented ·

Hi @Jouky D, was Jouky D's or Felix's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.

0 Likes 0 ·
Jouky D avatar image Jouky D Julie Weller commented ·
I don't know why sometimes I can't accept the answer. Could you accept it for me? Or solve this issue please? Thank you!
0 Likes 0 ·

1 Answer

Jouky D avatar image
0 Likes"
Jouky D answered Jouky D commented

I found this function: getvartype. It return 1 when I give an integer and 2 when Object.

I would accept the answer, however, I would like to know if there is a way to use "if error" in flexscript. Like, if I use a function for numbers in an object, use this to know that value is not a number.

· 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.

Felix Möhlmann avatar image Felix Möhlmann commented ·

You'd use a standard if-condition to do this check.

Variant num = "test1";
if(num.type == VAR_TYPE_NUMBER) {     // It is a number } else {     // It is not a number }
2 Likes 2 ·
Jouky D avatar image Jouky D Felix Möhlmann commented ·
Thank you!
0 Likes 0 ·