Notifications
Clear all

[Closed] variable type from Value*

I have an extension I am writing that has a fn that can accept multiple input types,float,color, etc… I am trying to find a way to detect what type of variable it is from the Value* in the arg_list. type_check won’t work since it throw an exception. I have tried using the tag variable but it doesn’t work for color. Any thoughts?

8 Replies
1 Reply
(@johnwhile)
Joined: 10 months ago

Posts: 0

write an example code… i don’t understand

Classof?

classof "test"
String
classof 1
Integer
classof 1.0
Float
classof (color 255 255 255)
Color
classof [255,255,255]
Point3
classof [0,1]
Point2
classof [255,255,255,255]
Point4

 

yes… classof and superclassof is the two function used for this purpose

case classof value of
 (
 	 Integer : ...
 	 Float : ....
 	 Color: ...
 	 default : ...
 )
 

Thanks for the examples but I am talking about the sdk and c++ not maxscript, hence the Value* variable. Example I have a function that I am exposing to maxscript.

Value* foo_cf(Value** arg_list, int count){
Value* bar = arg_list[0];
//how do i determine what kind of data is in the Value bar? can’t use type_check() because
// it will throw an exception

  if(bar->tag == class_tag(Float){//this one works

  }
 else if(bar->tag == class_tag(Color){//error since the Color class doesn't have a tag.

 }

}

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

it has to be ColorValue instead of Color:


  def_visible_primitive(checkValue, "checkValue");
  Value* checkValue_cf(Value** arg_list, int count)
  {
  	check_arg_count(checkValue, 1, count);
  
  	if (arg_list[0]->tag == class_tag(ColorValue)) mprintf("it's a color
");
 	else mprintf("it's not a color
");
 	return &ok;
  }
  
  

That did the trick thanks, I thought had already tried that one but ColorValue was showing as undefined. Looks like I may have needed to include color.h. Thanks again.

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

probably “colorval.h”

It might be worthwhile to check out the Function Publishing mechanism in the SDK. This will take care of type checking and conversion from mxs to C++ and vice versa for you.