[Closed] Class undefined??
Hi all!
I have problems using a custom material that we created for making our games. It’s based on DX material. I made a macroscript with different utilities to manager this material: assign material to object, convert to and from max standard material,etc. But when I try to use any of the utilities that use our material class I get this:
Type error: Call needs function or class, got: undefined
But if i open the macroscript in maxscript editor and evaluate all, then it works!!, the class is defined and I can use my material utilities. is there any way to make it work the first time, without using the Evaluate all option?
thanks!
Alberto Moreno “Grihan”
Crocodile Entertainment
http://www.crocoware.net
Is the custom material you’re referring to a Scripted Material Plugin that is defined further up in your script?
If so – that’s why the class is undefined when you run your management utility before evaluating the script. By evaluating the script, the class actually gets created and registered to 3ds Max. Without that evaluation, the material basically doesn’t exist.
The best solution to this is to separate the scripted plugin code from your management utility code and place that code in a .ms file somewhere in your plugin paths (can even create a new plugin path, just make sure you add it to the plugin paths via the plugin.ini or the 3ds Max interface).
That way, when 3ds Max stats, the script will always be evaulated, and the material will be available to you from the get-go.
You would have to do this on any machines the material might be used – including render nodes (don’t think that applies to a DX-based material, but mentioning it just in case) – just as you would a regular plugin.
No, it isn’t. The custom material is defined via a .ms that is in \scripts\startup folder, so it is started up when I start 3dsmax. So it has no sense that the class begins to be defined only when I evaluate my utility, because in this utility the material is not defined.
I found a solution!
I was using this, and it didn´t work:
i.material = CrocomatStandard()
but I put this, and it works!!
tempMaterial = CrocomatStandard()
i.material = tempMaterial
it works, but i want to know why…any suggestion?
Still sounds like scoping. Do you have the functions being defined located in
<max root>[i][i]\stdplugs\stdscripts\ ? or <maxRoot>\plugins\Scripted Global Functions?
You could also try
[/i][/i]i.material = ( CrocomatStandard() )
[i][i]
[/i][/i]