Notifications
Clear all

[Closed] MaxScript newbie question – test if object exists?

I have this bit in my script:

on slice2xbreakout changed true do
(
if isvalidnode $TNCG_SLdummy2 == true then ($TNCG_SLdummy2.pos.controller.x_position = (globalbreakout.value+slice2xbreakout.value)) else print “why is this not working?”
)

slice2breakout and globalbreakout are spinners defined elsewhere.

The reason I do the “isvalidnode $TNCG_SLdummy2 == true” test is to find out if the object exists in the scene to avoid a script break if the user rolls the “slice2breakout” spinner when the object is not present.

If the object exists in the scene, I can type isvalidnode $TNCG_SLdummy2 in the listener and it returns “true”, but running it in the script and moving the spinner returns “false” (which I confirm by printing “why is this not working?” to the lisenter) – no matter what I do.

Eliminating the test and going straight to $TNCG_SLdummy2.pos.controller.x_position = (globalbreakout.value+slice2xbreakout.value) works perfectly but makes then then script breaks if the user rolls the spinner without the object being present in the scene.

I also tried isdeleted and it gave me the same exact result.

Any ideas what I’m doing wrong? Is there a simpler way to check for an object existing in the scene in this context?

3 Replies

how about:

if $TNCG_SLdummy2 != undefined then

That worked! Thanks a bunch! I wonder why the other route didn’t work though?

Because isValidNode assumes the object exists and attempts to access it’s properties. If it is undefined, then it doesnt exist.