[Closed] float_script supported in Max7?
I’ve got a user running a script of mine who keeps getting the following error:
-- Unknown property: "addNode" in Controller:Float_Script
He’s the only user (so far) with this problem. Would it have anything to do with the fact that he’s using Max7? Many thanks.
Yup – adding nodes and such like is a max 8+ thing.
You’ll have to reference the node manually in your script for max 7, and use a “dependsOn”.
Dave
Note that by “refer manually” – more correctly, “refer explicitly”, you’ll run into a problem (which is exactly why it was fixed in r8)…
If this is the script code (double a particular sphere’s radius) in pre-r8:
$Sphere01.radius * 2
Then the object getting renamed – a rather benign operation – will make the script error out (unless there’s another object named “Sphere01”, of course).
Typical work-around for this is to reference the node’s handle instead.
-- get $Sphere01's handle
theHandle = $Sphere01.inode.handle
theSphere = maxOps.getNodeByHandle <value of theHandle>
theSphere.radius * 2
Note that this will break if you merge the object that has the controller into a new scene, even if you merge $Sphere01 with it, as the node handle gets changed. So it’s a ‘unique ID’, but only for any given scene. Which is poo, but there you go.
A bit more robus would involve you setting up a Custom Attribute, or use setAppdata, on Sphere01 and set a more unique value (perhaps using genClassID() or some other random generator that is likely to be unique), which you can then find again in the scene by looping over all the (appropriate) nodes yourself in the controller; this’ll slow the controller down a good bit, so might be something you want to handle by only finding that object once, and then caching that object in a (global) variable.
Fun stuff, eh?
Aha. Thanks, Dave.
Now, all my MXS experience is post-Max8, so bear with me here. I’ve currently got something like this:
-- make a box, a sphere and a dummy
b = box()
-- add a customAttribute "chum" to the box
custAttribute.add b ca
d = $dummy()
s = sphere pos:[50,0,0]
-- make the dummy the parent of the box
b.parent = d
-- make the sphere the box's chum
b.chum = s
-- create a float script
fs = float_script()
d.rotation.z_rotation.controller = fs
fs.addNode "obj" b
fs.script = "paramWire.connect2Way obj.rotation.controller[#z_rotation]\
obj.chum.rotation.controller[#z_rotation] (\"Z_Rotation\") (\"Z_Rotation\")"
In retrofitting this to be Max7-compliant, would the dependsOn go inside the fs.script? And would it read dependsOn b b.chum d ? Many thanks!
Edit: Thanks as well to you, ZBoxx (guess our posts crossed in cyberspace). My question remains, though, where to place that dependsOn. This business is hampered by the fact that I don’t have direct access to Max7.