ScriptSpot

Forum topic · General Scripting

Question about "Execute"

By Romeh · 2013-08-09

Description

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 (14)

.

miauu · 2013-08-09

Glad to help. :)

.

miauu · 2013-08-09

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 · 2013-08-09

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 · 2013-08-09

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 · 2013-08-09

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

Romeh · 2013-08-09

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 · 2013-08-09

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

Romeh · 2013-08-09

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 · 2013-08-09

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 · 2013-08-09

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 · 2013-08-09

Hi Kostadin,
This does not apply to you :)

barigazy · 2013-08-09

BTW Romeh your last example is a total mess :) No hard feelings. ;)

Romeh · 2013-08-09

hehe, yeah that was a big mess :)

Thank you barigazy & miaou
Two different methods, seem to exist so many ways to do the same thing in maxscript...
I'll see it tomorrow, i think it will be probably ok

thanks

barigazy · 2013-08-09

Yup. In MXS can do same things in few different ways. That's the power of this scripting languade. But only GOD knows which way is the best :)
Just keep it simple that's the basic rule.