ScriptSpot

Forum topic · General Scripting

Can anyone tell me the problem here? :-)

By ce89 · 2013-01-31

Description

Can't seem to get this simple example to work. Any help would be much appreicated.

rollout myTest "My test" (
curmaxFileName = maxFileName
newMaxFileName = substring curmaxFileName 1 9
Messagebox (newMaxFileName as string)

)
createDialog myTest

Comments (6)

barigazy · 2013-01-31

In the previous post Panayot gave you a very detailed explanation about everyting you need to know about "rule of thumb".You need to store all interface functions or structs inside button event or use variables if you want to define your custom function

try(destroyDialog ::testRoll)catch()
rollout testRoll "test"
(
button render_btn "render"
on render_btn pressed do
(
if renderSceneDialog.isOpen() do renderSceneDialog.close()
rendSaveFile = on
rendOutputFilename = (maxFileName + "//" + "sub folder" + "//" + "test.tga")
max quick render
)
)
createDialog testRoll

ce89 · 2013-01-31

No probs, I'll keep trying to work this one out. I was more after general protocols and I guess you are right in that Panayot described some of these quite well. The thing is when you are fairly experienced with all the associated terms everything makes sense straight away.

I will take your advice and look over all these things again. I would post my end goal, but I kind of want to get there with a little help but not have someone do it all for me, hence the guidance and not "can someone write this for me".

Thank you both for your help. I think you have given me a few things to consider and look at.

+1

Anubis · 2013-02-01

I alsway glad to meet peoples who not ask someone to do their entire job. It's correct to make example code where to isolate the problem. Keep going like this ;)

Hi Claire

Anubis · 2013-01-31

There a lot of problems in this code :) but then ask question please tell us what's the main aim, else you may get a bit chaotic help :)

What I'll say is almost the same.

*

maxFileName

is a read-only variable that will be empty string if the current scene is Untitled.

* If you need (by some reason) to show only first 9 characters, need to be sure if the string length is larger than this value.

-- something like this:
strLength = maxFileName.count
curmaxFileName = \
if strLength == 0 then "Untitled" else
(
	if strLength > 9 then
		substring maxFileName 1 9
	else maxFileName
)

* Next but more grave problem is that you try to use

Rollout

as replacement of

Function

:) For example, if you just copy/paste my code into the body of your rollout... hehe, read the error message ;)

In the body of the Rollout you can declare local/global variables, functions, etc., but calling functions (and MessageBox is also function) can do that only from some of the Events of the Rollout itself (like #open), or from the Events of UI-controlls inside (like button #pressed, etc.).

Cheers!

ce89 · 2013-01-31

Firstly thanks for the examples barigazy. Most helpful.

Anubis,

Sorry for the confusion. I left a few other code lines in because I was having problems accessing certain code lines. From a bit more researching I think this has more to do with "scoping" I think? I have looked through the scoping info but it still doesn't seem very clear. Is there any "rule of thumb" to use with scoping if this is the problem.

Another example of what i am testing. This too doesn't work.

try(destroyDialog ::testRoll)catch()
rollout testRoll "test"
(
renderSceneDialog.close()
curmaxFileName = maxFileName + "//" + "sub folder" + "//" + "test.tga"
rendSaveFile = on
rendOutputFilename = curmaxFileName

button render_btn "render"

on render_btn pressed do
(
max quick render
)

)
createDialog testRoll

Many thanks for any help.

barigazy · 2013-01-31

You need to have saved current file, and if you want to show messageBox just use


Messagebox (maxFileName) title:"Current File Name" beep:off

or in your case solution with button


rollout testRoll "test"
(
	button btn "Get Current File Name"
	on btn pressed do (Messagebox curmaxFileName)
)
createDialog testRoll style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

or solution when rollaut open

try(destroyDialog ::testRoll)catch()
rollout testRoll "test"
(
on testRoll open do (Messagebox curmaxFileName)
)
createDialog testRoll style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)