Home Technical Talk

maxscript --Type error: Call needs function

Hi guys!

I'm working on a simple tool in maxscript for my own practice. The script works fine when I'm testing it out, however, when I shutdown max and start the tool for the first time, I get the following error:

--Type error: Call needs function or class, got: undefined

But when I close the rollout and re-run the exact same script a second time, it works fine. It seems like the error is telling me that I haven't defined a function correctly. Not sure what I'm doing wrong.

Any ideas or feedback are appreciated.
Thanks!

Replies

  • monster
    Offline / Send Message
    monster polycounter
    In your tool a function is being defined after it is used. It works on the second try because its defined at the end of the first pass.

    If you script is a single file, move all you function definitions to the top of the script. If you script is multiple files check this page for the evaluation order.

    http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-615D14FB-0F2D-4801-B381-1128C4128C70.htm,topicNumber=d30e31465

    Finally, we can help better if you post a code sample.
  • theStudent
    Whoops, I meant to post my script. However, what you said makes sense! Thanks for the response. Testing it now.
    brb =]

    macroScript testScript
    category:"some category"
    toolTip:""
    (
    try(closerolloutfloater rof) catch("Dialog close error!")
    rollout test "Production Tools" (

    group "Production Tools" (
    button btn_K "tempTXTR" width:50 height:30 align: #left
    )

    on btn_K pressed do (
    tempTXTR ()
    )

    )
    rof = newrolloutfloater "Sim Tools v1.0" 300 90
    addrollout test rof
    --end main******************************************************************************************************************

    fn tempTXTR = (
    obj = selection
    obj.wirecolor = color 0 0 255
    obj.material = meditMaterials[1]
    obj.name = "test"
    )
    )
  • theStudent
    Thanks monster! Read the link, that and your post helped clarify my error. :)
  • Pathologist
    Offline / Send Message
    Pathologist polycounter lvl 4
    Just a side note, I would change your function to:
    fn tempTXTR obj = (
    	obj.wirecolor = color 0 0 255
    	obj.material = meditMaterials[1]
    	obj.name = "test"
    )
    

    this way when you call your function you can add the "object" behind it, eg;
    on btn_K pressed do (
    	tempTXTR selection -- same as declaring obj = selection at the start of the function
    )
    

    or;
    on btn_K pressed do (
    	tempTXTR objects -- uses all objects in the scene
    )
    

    Now you can make multiple calls towards the same function without having to duplicate functions! :)
Sign In or Register to comment.