"WARNING: ReferenceError: getNodeParent is not defined" for DzDistantLight::getNodeParent() ??
I'm a little rusty since I haven't looked at any DAZ script for half a year. Here's a code snippet that's crashing my script...
print("wbNode="+wbNode)
print("wbGndNode="+wbGndNode)
print("wbSunNode="+wbSunNode)
print("wbIblNode="+wbIblNode)
// Parent the sun to the worldball (N.B. WORLDBALL + SUN NEED TO BE ZEROED FIRST !!! )
var oParent=wbSunNode.getNodeParent();
if (oParent && oParent!=wbNode){ // If the sun's already parented to anything except the worldball it must be unparented first
oParent.removeNodeChild(wbSunNode); // no second parameter given (so inPlace=false)
}
...and this is what ends up in the logfile when I run it in DS 3.1 ...
DEBUG: wbNode=DzNode(name = "WorldBall")
DEBUG: wbGndNode=DzNode(name = "WorldBall Ground DS3")
DEBUG: wbSunNode=DzDistantLight(name = "WorldBall Sun")
DEBUG: wbIblNode=DzShaderLight(name = "WorldBall IBL")
WARNING: Script Error: Line 1854
WARNING: ReferenceError: getNodeParent is not defined
WARNING: Stack Trace:
()@:1854
()@:1946
()@:-1
Error in script execution!
...or in DS 4.6...
DEBUG: wbNode=[object Object]
DEBUG: wbGndNode=[object Object]
DEBUG: wbSunNode=[object Object]
DEBUG: wbIblNode=[object Object]
WARNING: Script Error: Line 1854
WARNING: TypeError: Result of expression 'wbSunNode.getNodeParent' [undefined] is not a function.
WARNING: Stack Trace:
()@:1854
Error in script execution!
Line 1854 is the 'var oParent=wbSunNode.getNodeParent();'
But the debug shows that wbSunNode is a DzDistantLight, and getNodeParent() is a valid member function (inherited from DzNode).
So why's it telling me getNodeParent isn't defined?
What's the obvious thing I'm missing/overlooking?
Comments
I don't know - I copied your script, copied the name of your variable from the print statement to a var declaration to get the light and it works - with or without a semicolon after the print statement, which is the only thing leaping out as a fault in your code.
Thanks Richard, that's actually a good start. I copied your version of my snippet to a new test.dsa, selected a distant light, and ran the snippet (i.e. without the preceding 1850 or so lines of my original). Got this in DS 3.1...
Executing DAZ Script file: H:/Studio/!ONGOING/Test.dsa
DEBUG: wbSunNode=DzDistantLight(name = "DistantLight 1")
Script executed successfully.
...and this in DS4.6...
Executing DAZ Script file: H:/Studio/!ONGOING/Test.dsa
DEBUG: wbSunNode=[object Object]
Script executed successfully.
I still haven't solved this, but I've run into another problem where a section of code works fine in isolation, but does something odd when it's part of the main 1600-or-so line script - "Update Prop Origin Only Working If I Display Message Boxes ???"
Although it's a different script, I'm wondering whether the root of the problem may lie somewhere in those other lines of code...
In your snippet, "wbSunNode" is assumed to be a valid DzNode object. Don't assume. Make sure that it is not undefined/null. As written, if a node is not selected you will get that error, since you are then attempting to call getNodeParent on a null, not a DzNode object.
-Rob
Agreed, I should check it's valid first (I wasn't checking). But if wbSunNode is undefined/null then why does the print statement earlier seem to indicate that it's valid?
Here's the chunk of code immediately preceding it (mainly for my own reference - I haven't looked at this for months):
Adding the check makes no difference (or probably I've done the check wrongly - it's been so long since I wrote any DAZ script!) - it thinks wbSunNode is valid
And running that in DS 4.6 I get this
Executing DAZ Script file: H:/Poser/3DCheapskate/runtime/libraries/Props/3DCheapskate/WorldBall/WorldBall Setup DS3,4 ~~~ ONGOING.dsa
...
(lots more of my debug)
...
Loaded file: WorldBall Setup DS3,4 ~~~ ONGOING.ppz
DEBUG: wbNode=[object Object]
DEBUG: wbGndNode=[object Object]
DEBUG: wbSunNode=[object Object]
DEBUG: wbIblNode=[object Object]
DEBUG: VALID wbSunNode
WARNING: Script Error: Line 1858
WARNING: TypeError: Result of expression 'wbSunNode.getNodeParent' [undefined] is not a function.
WARNING: Stack Trace:
()@:1858
Error in script execution!
Ran tdlmake on image H:/Poser/3DCheapskate/Runtime/Textures/3DCheapskate/ReflectionMaps/E03SandLL1024INV.jpg
With this check...
...I get ...
DEBUG: wbSunNode=[object Object]
DEBUG: wbIblNode=[object Object]
DEBUG: wbSunNode seems OK
WARNING: Script Error: Line 1858
This smacks of self-screwing-up code! Which could explain why sometimes other odd things happen.
Try printing the className() for your objects - it looks as if they are there but not what you expect.
Thanks Richard, just tried that and you're right - they're not nodes (and it's so obvious! Look where the 'getLabel()' is! )...
...and got this...
...
WARNING: Script Error: Line 1848
WARNING: TypeError: Result of expression 'wbNode' [undefined] is not an object.
Then I noticed that wbNode, wbSunNode etc are all strings, not nodes - they're set up with wbNode=xyz.getLabel()
I thought that this would explain things, but...
...but here's the same section in the original version of the script (with an extra print to confirm the section of code is actually being run), which works. I've also added a comment to show where I inserted new code to crash it...
...and the log file...
Loaded file: WorldBall Setup DS3,4.pp2
DEBUG: Just to check I'm running this section of code
DEBUG: @@@ oMatWb.name=Preview
Compiled C:/Users/c/AppData/Roaming/DAZ 3D/Studio4/shaders/brickyard/{b90ce5c2-776d-4dd4-b150-7a9cfa847205}/shader_Surface.sdl...
Script executed successfully.
... and here's the same section with the crashing code inserted...
The 'Apply worldball material bit at the end continues like this...
So in my origibal working version of the script this.m_oNode is being set as a single character, the first character of the label.
I'm surprised that g_oPresetHelper.collectMaterials() and/or getObject() don't crash ?
So wbNode was always intended to be a DzNode, not a string.
I therefore assumed that correcting the getLabel() bit would resolve things, but...
If I remove the getLabel() then the script with inserted code no longer crashes. But it always does the 'wbSunNode is undefined' bit
So I've got something screwed up when I set up allNodes[], either here...
...or here...
Oh dear, I'm talking a load of rubbish here ! :oS
Did I say I'm a little rusty in the OP? More like totally seized up and in need of a good whack with a mallet! LOL
I'm not setting wbNode, etc to a string with xyz.getLabel() - I'm passing xyz.getLabel( as a parameter to getOurNode() , and setting wbNode to whatever that returns.
And although the function getOurNode() was in the original script it was never called till I inserted this new code...
Finally ! And so stupid... as usual. getOurNode() is totally unnecessary :D
Now just got to find out what that oHand should be... I obviously just cut-and-pasted a chunk of code from my Smart+ Prop stuff.