Home Technical Talk

MaxScript, include Vs FileIn, and RollOuts

polycounter lvl 10
Offline / Send Message
trebor777 polycounter lvl 10
Hello people, been playing with Maxscript for a month, full time :p it's great and all, but there are still a few things I don't get :poly127:

Like this problem:
This is a reduced but valid i think version of my code
rollout myRollOut "My Rollout :D" width:216 height:462
(
	include "$scripts\myRollOut\UI\SelectCharID.ms"
	
-- ################### MAIN UI & VARIABLES ##############	
	groupBox grp1 "File" pos:[6,7] width:204 height:113
	button NewProjBtn "New Character Project" pos:[16,24] width:188 height:24
	button OpenProjBtn "Resume Character Project" pos:[16,56] width:188 height:24 toolTip:"Reset the Scene..."
        
        local TempCharID
-- ################### FUNCTIONS ########################

	fn GetCharID = (
		oldID = TempCharID
		CreateDialog SelectCharID modal:true  -- This call the Rollout that we just included in the def. 
		if TempCharID != oldID then ( -- CharID has been properly set so let's go !
			return TempCharID
		)
		undefined
	)

)	

and this is the included rollout
rollout SelectCharID "Select Character ID" width:232 height:96
(
	GroupBox grp1 "Select Character ID" pos:[8,8] width:216 height:40
	edittext edt1 "" pos:[16,24] width:200 height:17
	button OkBtn "OK!" pos:[128,56] width:96 height:32
	button CancelBtn "Cancel" pos:[8,56] width:96 height:32
	
	on edt1 entered val do
	(
		OkBtn.pressed()
	)
	on OkBtn pressed do
	(
		if edt1.text != "" and (edt1.text as Integer) > 99 then (
			myRollOut.TempCharID = edt1.text
			DestroyDialog SelectCharID
		)
		else (
			messageBox "Empty or Incorrect ID: Should be a Number > 99"
		)
	)
	on CancelBtn pressed do
	(
		DestroyDialog SelectCharID
	)
)

Basically when the function wants to create the dialog, it says it doesn't find the rollout (undefined), when it has been included just before. (include "$scripts\myRollOut\UI\SelectCharID.ms")
(this function is called when the user clicks one of the button of the main ui)

I don't get why it's crashing... the file seems to be included fine, (i did a print just before the rollout definition and got the message)
so ... what's wrong?
Is it a Scope error? Cause, wherever i put the include line, (in the function, or outside the main rollout) it still crashes.

I'd like to keep my code separated in several files, it's a bit easier to maintain...

Any ideas?



EDIT: After some investigation, it seems to not work when i'm calling the main script through a MacroScript definition
macroScript myMacro
	category:"my Tools"
	toolTip:"my Tool"
(
	filein "$scripts\MarioPlumber\myRollOut.ms"
)
It works fine, if I execute the script directly...
kinda weird.

Final EDIT: Ok, now it works:
It's because the macroscript file was defined in the usermacro folder rather than the startup folder of max.
as explained here: tech-artists.org/wiki/Macro_installation_(MAXScript)

Replies

Sign In or Register to comment.