Type detection?

randall's picture

Hey guys,

Anyone aware of a super easy way to detect a type? Trying to detect whether a virtual output is a structure or a number. Willing to use JS if needs be.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cybero's picture
Re: Type detection?

Try this - uses Composition Info, could be run in a separate window if taking an URL to a composition.

URL can be ./nameoffile.qtz, at directory root level.

PreviewAttachmentSize
blankinfo.qtz3.98 KB
blanksource.qtz5.88 KB

usefuldesign.au's picture
Re: Type detection?

You can count the structure and if it's non-zero you have a structure.

Testing a structure by evaluating it in a math patch (a==b?1:0) will semi-crash the composition such that no layers 'above' the layer falling over will render so that's not a great way to do it but as a hack it works.

Unfortunately in JS the typeof function just returns object for any object nothing more specific. I messed with using

try
{
   some maths on mystery object
}
catch(err)
{
   well that didn't work it must be a structure
}

but javascript think it is performing math even on a structured object and I was getting some weird results anyhow so left it alone.

The second attached composition shows you how to use the .constructor method to determine some types. Hope it helps.

PreviewAttachmentSize
types.qtz13.33 KB
JS objectTypeName III.qtz28.17 KB

gtoledo3's picture
Re: Type detection?

Are you asking if one can id the type, as in "virtual, mesh, image, structure, color, number, etc."?