PDA

View Full Version : Rci.AddHandler problem...


zortech
01-04-2008, 05:18 PM
Hey,

I'am currently using the Rollout Creator function. The script generates a couple of buttons in a loop and then adds events to them by using the following line of code:

rci.addHandler ("btn_" + (i as string)) #pressed codeStr:("fn_test()")

"addHandler" basicly works fine, but when I try to run a function I get the following error:

-- Error occurred in btn_1.pressed()
-- Frame:
-- fn_test: undefined
>> MAXScript Rollout Handler Exception: -- Type error: Call needs function or class, got: undefined <<

Here's the function I used to test...

function fn_test =
(
messageBox "test" title:"Bla"
)


If I use the messagebox example from the maxscript file, or general functions like Render() it works perfectly fine...

Bobo
01-04-2008, 05:43 PM
Hey,

I'am currently using the Rollout Creator function. The script generates a couple of buttons in a loop and then adds events to them by using the following line of code:

rci.addHandler ("btn_" + (i as string)) #pressed codeStr:("fn_test()")

"addHandler" basicly works fine, but when I try to run a function I get the following error:

-- Error occurred in btn_1.pressed()
-- Frame:
-- fn_test: undefined
>> MAXScript Rollout Handler Exception: -- Type error: Call needs function or class, got: undefined <<

Here's the function I used to test...

function fn_test =
(
messageBox "test" title:"Bla"
)


If I use the messagebox example from the maxscript file, or general functions like Render() it works perfectly fine...

What is the scope of the function definition? The rci methods create a rollout in a similar fashion to building the rollout definition as a large string and calling execute() on it. Any code evaluated using execute() is evaluated in global scope, not in the scope where execute() was called.
This means that fn_test should be global to be visible to code inside the automatically generated rollout. If you were building a rollout manually, the function would have been probably in the scope of the rollout, but it is tricky to put a function inside a rollout created out of your control. Try defining fn_test as global BEFORE running the rollout creation and see if it visible.

If you need a bunch of functions, you can combine them inside a global struct.
Also, if you want your function to access controls and other code inside the automatically generated rollout, you would have to pre-declare the variable of the rollout as global before the function(s) the rollout will be calling. Then you will be able to prefix variables containing UI controls with the name of the rollout variable to access them inside.

That being said, I haven't used the RCI methods much and might be missing some details...

U.S.S. Speed
01-04-2008, 05:43 PM
Dunno if this could help...

But I notice in my script that if I create a function without any supplied variable, it returns often the error you got...

So, I got used to add a dummy variable to all my function who doesn't need any...

Got rid of the error.

Of course the error could be something totally different. <shrug>

[edit] Or simply what said Bobo. :)

zortech
01-04-2008, 06:05 PM
Thanks alot for the quick response Bobo & U.S.S. Speed.

Defining the function as global works fine! Thanks for the hint Bobo!

Note: I stumbled across the rci.addText function to generate functions within generated rollouts. As it's going to be a simple function I'll try that one too.

CGTalk Moderation
01-04-2008, 06:05 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.