[Closed] "fileIn" in "on pressed" event handler
hi everyone!
can someone please tell me how to create a script that runs another script after pressing a button??? something just like the “Run Script” button in the MaxScript utility
this is where my problem is:
on myButton pressed do
(
fileIn "script.ms"
)
the script works fine if “script.ms” doesn’t contain any errors… BUT if it does, it screws up the script thats running it and gives me a Rollout Handler Exception… and when that happens the button just doesnt work anymore and you have to reload it again.
i also tried this:
on myButton pressed do
(
try
fileIn "script.ms"
catch()
)
this stops the rollout from freezing but it also doesnt send out errors from “script.ms”, if any.
basically what i want is a dialog that runs a script BUT also returns errors in the script being run…
Thanks
Hi,
I think your structure is wrong. You should load all your functions, and then when the button is rpessed, call the function. If you functions are contained in another script, then that script should be loaded from the beginning.
What are you trying to do?
J.
filein a_script_with_all_my_function_in_it
on myButton pressed do
(
do myfunction
)
Basically what im trying to do is create a script that just runs another script on the push of a button… ya know the MaxScript utility in the utilities panel? i want something like that, except that the script knows what file you want to run and won’t keep asking you all the time…
btw i’ve tried to put it in a function and call the function once the button is pressed and that does’nt work either… i’ve tried so many variations its not funny 🙁
thanks for the reply
Hi Jimothy,
I understand what you mean now! if you do a FileIn, the loaded script is executed line by line as if it is part of the original script, so if there is an error, then it will stop execution of the script. so i think the short answer is – no.
I’m curious, why are there erros in the script that you’re loading?
J.
hey da_j_man,
the wierd thing is, is that it works if i use filein inside a “on blahblah open” works. An error is given, BUT the dialog still runs. Also, doesn’t the “inlcude” command include external scripts as they were apart of the original?
Wait a sec… i just thought of something else… in my first and second post, i mentioned the MaxScript utility right? if you use that to run a script it works how i want my one too… If you have an error in the script being run, it gives you the appropriate error but still remains functional. What i did notice though, is that the error is different…
i get:
MaxScript Rollout Handler exception: blah, blah
while the MaxScript utility gets:
MaxScript FileIn Exception
So thats why i reckon it should work… if MaxScript utility works… why can’t it be replicated??
anyways… in regards to your last question: “why are there erros in the script that you’re loading?”
The reason why i want this basic dialog box is so that i dont have to use Max’s script editor… it gets pretty annoying sometimes. So basically, say i was working on a script… i just wanna be able to save the script im working on (in the external editor), ALT-TAB back into MAX and press “RUN” on my script runner to test out the code. Since im still creating/testing the script you seen how i might still have errors in the script im running…
With the MaxScript utility… i’ll have to press “run script”, then choose the script im running then press ok. Choosing the “script to run” all the time is unneccessary and annoying if you’re just working on the one script
Hey if you absolutely need to run the script from outside you could maybe use something like this:
on myButton pressed do
(
try(
fileIn “script.ms”
)catch(messagebox “script error”)
)
that way you will get a messagebox everytime the script fails.
CML
yeh… ive tried that… since im running scripts that may have errors in them i want the script to give me the errors and where they occured so i can easily debug it.
if only there were a way to print the actual error in the body of the “catch”…
Hi jimothy,
Why don’t you use a log file ?
You print some information in a file located on your hard drive in some parts of your script and so when you get into your catch block you can check your log file to see where it stopped.
What I usually use something like that :
fn myfuncforfun parm1 parm2
(
try
(
print (“myfuncforfun begin”)
…
code
…
print (“myfuncforfun end”)
)
catch( print (“crash in myfuncforfun”)
)
etc…
This way you can trace where it crashes so you can fix the problem.
This is the usual way we debug things in release builds in C++ for example.
Regards,