Notifications
Clear all

[Closed] Functions + Rollouts = Undefined

I’ve never been able to get many functions to work when called from a rollout. I often get an undefined error.
What is it that I have to decalare as global and where in the script do I have to do this to get function that are defined above the rollout to work? And how?

I’ve always just ignored the problem before and decided not to use functions cause I’ve never been able to get anything more than a simple function to work with rollouts. But I really want to know how to get it to work now cause I feel it’s limiting me in what I can do with maxscript.

When I’m able to get the function working with the rollout I want to delve into callbacks that execute the function and the way that I have the script working now without the GetDispProp function, I’d have to double-up on some of the code which I’d prefer not to do.

I have 2 versions of the macroscript:

1/ This one works properly when you hit the get proerties button (with an object selected), but it doesn’t use a function to do this as I would like it to.
http://home.iprimus.com.au/wickergray/CgRayDispFloatNoFunction.mcr

2/ This version has the function implemented, but when you hit get properties button, it errors with the message “Unknown property: “checked” in undefined” I know that it’s saying that the variable chkbut_DisplayShad is undefined, but is it this variable (and others like it) that I have to define as global? Or is it the rollout that I need to define as global as I’ve seen other people do? And where do I need to do this?
http://home.iprimus.com.au/wickergray/CgRayDispFloatWithBrokenFunction.mcr

Many thanks,

Cg.

6 Replies

The function needs to be either within or above the rollout that calls it.

Either that or you are attempting to call variables which are not global.

Often you will want within a function to change a value within a rollout. In such a case you need to use the explicit path to the rollout value.

i.e.

dialog.subrollout.rollout.object.value

I just posted a script which uses a function within a rollout. The function is “global” so to speak in my script and in order to call a specific rollout I would probably need to use the execute () operator and include the rollout’s name/location in the call of the function.

i.e.

fn changethingstotwo where = (
execute (where+”.value = 2″)
)

rollout stuffs
(
button btn “button”

on button pressed do
(
current = “stuffs.btn”
changethingstotwo current
)
)

The problem here is that the functions are defined before the UI elements. In this case your checkbutton “chkbut_DisplayShad” is giving you the error because it is accessed in the function. All you have to do is define the functions after the buttons. I moved the buttons up and it seems to work fine.

Thanks both for your answers. Stev I tried what you mention and yes it works great. I was under the impression that functions should be up the top of the script though. What’s the rule with that?

There is no real rule. But generally if I am only using a function in a rollout, I just keep it in the rollout.

Stev

I tend to assume maxscript exclusively works from top to bottom. Even though sometimes it doesn’t and I’m not really experienced enough to know why.

I do know that max doesn’t like anything above buttons in rollouts or in between buttons in rollouts.

So if you want a function that calls something. Put it below it. If you have a block of code that calls the function put the code below the function.

“Call up” “Define down”. And if you’re outside “Be global, be absolute”.

Can’t thank you guys enough… Cheers.

Cg.