Question about "Execute"

Hello,

i have a simple question, i am a little bit lost with maxscript, so, if you can help it will be so nice ;)

i think its probably really simple, my question is: Do you know an alternative to "execute" to do this stuff :

fn LogoPreset1 = ( print "logo1" ) 
fn LogoPreset2 = ( print "logo2" ) 
fn LogoPreset3 = ( print "logo3" ) 
 
rollout testrollout "test" width:272 height:120 ( 
	dropdownlist dd items:#("hello","hello world","hello you") height:6 
	button addb "add logo" pos:[50,35] width:125 height:32 
 
	fn w = 
		( 
			z = dd.selection as string 
			execute("LogoPreset"+z+"()") 
			) 
 
			on addb pressed do ( 
		w() 
		) 
 
 
		) 
 
 
createDialog testrollout

Because of "execute" i have to put fn before the rollout, but doing that complicate some other part of my main script.

so its why i'm looking for an alternative

thank you for your help.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

Glad to help. :)

miauu's picture

.

Is this is what you want?

rollout testrollout "test" width:272 height:120 
( 
	--------preset----
	--preset1
	local thename1 = "Roger"
	local theplace1 = "here"
	local descript1 = "hello world 01"
	--preset2
	local thename2 = "henry"
	local theplace2 = "anywhere"
	local descript2 = "hello world 02"
	--preset3
	local thename3 = "jack"
	local theplace3 = "somewhere"
	local descript3 = "hello world 03"
 
	local namesArr = #(thename1, thename2, thename3)	
	local placesArr = #(theplace1,theplace2,theplace3)
	local descriptArr = #(descript1,descript2,descript3)
 
	dropdownlist dd height:6 items:namesArr
	editText et_place "Place:" pos:[16,60] width:238 height:15	
	editText et_description "Description:" pos:[16,80] width:238 height:15
 
--I trying to : When i select name in droplist, "description" en "place" text appear in --nametxt and placetxt....
	on dd selected idx do
	(
		et_place.text = placesArr[idx]
		et_description.text = descriptArr[idx]
	)
--rest of the code is a big mess... useless to post it :(
 
)
createDialog testrollout

If this is not, give us an example of what have to be printed in the edittext boxes when you change the ddl selection.

Don't use so many global variables when you can use local variables.

Romeh's picture

omg! yes! I making so many

omg!
yes!
I making so many mistake! thanks for advice

I think it's exactly what i needed!
Just the time to understand how it work and I'll include it in my script.. it will be probably ok

many thanks for your disponibility.

Romeh's picture

more code : totally

more code :
totally approximative but ...

rollout testrollout "test" width:272 height:120 ( 
	--------preset----
--preset1
global thename1 = "Roger"
global theplace1 = "here"
global descript1 = "hello world 01"
--preset2
global thename2 = "henry"
global theplace2 = "anywhere"
global descript2 = "hello world 02"
--preset3
global thename3 = "jack"
global theplace3 = "somewhere"
global descript3 = "hello world 03"
 
global listfull = #(thename1 as string, thename2 as string, thename3 as string)	
 
	dropdownlist dd height:6 items:(listfull as array)
	editText nametxt "Place:" pos:[16,60] width:238 height:15	
	editText placetxt "Description:" pos:[16,80] width:238 height:15
 
fn changeinfo = (
	x = dd.selection
	nametxt.text = thename+x as string ---??? something can make thename+x = thename1 or thename2 etc....
 
)
 
 
on dd selected i do (
	changeinfo()
 
)
)
 
createDialog testrollout
 
 
 
barigazy's picture

...

Workaround
Use one function for the all ei.

-- if you use this form place this function after rollout controls definitions
fn printLogos num:dd.selection =
(
	format "Logo%\n" num
)
printLogos()
--or you can use this form and put fn above roll definition
fn printLogos num: = format "Logo%\n" num
printLogos num:dd.selection

barigazy

Romeh's picture

Thank you for the answer that

Thank you for the answer that was fast! ;)

it work, but in fact i want to make a more complicated fn than just format or print some thing.

Thank you very much for the lead, i am working on it..

i will be back soon ;)

barigazy's picture

...

I know that you have more comlicated question ;)
Post what you have to see the problem.

barigazy

Romeh's picture

so... Another one example of

so...

Another one example of what i want to do.. really sorry for my first question i didn't know how to explain my goal, ihope this one is more accurate.

i think it' probably really easy to do... but i'am stucked

rollout testrollout "test" width:272 height:120 ( 
	--------preset----
--preset1
global thename1 = "Roger"
global theplace1 = "here"
global descript1 = "hello world 01"
--preset2
global thename2 = "henry"
global theplace2 = "anywhere"
global descript1 = "hello world 02"
--preset3
global thename3 = "jack"
global theplace3 = "somewhere"
global descript1 = "hello world 03"
 
global listfull = #(thename1 as string, thename2 as string, thename3 as string)	
 
	dropdownlist dd height:6 items:(listfull as array)
	editText nametxt "Place:" pos:[16,60] width:238 height:15	
	editText placetxt "Description:" pos:[16,80] width:238 height:15
 
--I trying to : When i select name in droplist, "description" en "place" text appear in --nametxt and placetxt....
 
--rest of the code is a big mess... useless to post it :(
 
)
 
 
createDialog testrollout
Romeh's picture

more code : totally

more code :
totally approximative but ...

rollout testrollout "test" width:272 height:120 ( 
	--------preset----
--preset1
global thename1 = "Roger"
global theplace1 = "here"
global descript1 = "hello world 01"
--preset2
global thename2 = "henry"
global theplace2 = "anywhere"
global descript2 = "hello world 02"
--preset3
global thename3 = "jack"
global theplace3 = "somewhere"
global descript3 = "hello world 03"
 
global listfull = #(thename1 as string, thename2 as string, thename3 as string)	
 
	dropdownlist dd height:6 items:(listfull as array)
	editText nametxt "Place:" pos:[16,60] width:238 height:15	
	editText placetxt "Description:" pos:[16,80] width:238 height:15
 
fn changeinfo = (
	x = dd.selection
	nametxt.text = thename+x as string ---??? something can make thename+x = thename1 or thename2 etc....
 
)
 
 
on dd selected i do (
	changeinfo()
 
)
)
 
createDialog testrollout
 
 
 
barigazy's picture

...

First of all you not need to use globals in this case also you convert string to string and array to array. Look et this example

try (destroydialog ::testrollout) catch()
rollout testrollout "test"
( 
	local items = #(
			#("Roger","here","hello world 01"), \
			#("Henry","anywhere","hello world 02"), \
			#("Jack","somewhere","hello world 03")
	)
	dropdownlist dd height:6 items:(for i in items collect i[1]) selection:2
	editText nametxt "Place:" pos:[16,60] width:238 height:15	
	editText placetxt "Description:" pos:[16,80] width:238 height:15
 
	on dd selected itm do (placetxt.text = items[itm][2] ; nametxt.text = items[itm][3])
	on testrollout open do (placetxt.text = items[dd.selection][2] ; nametxt.text = items[dd.selection][3])
)
createDialog testrollout 272 120 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.