Notifications
Clear all

[Closed] [solved] On Button pressed do Multi_Random_fn1,,fn2,fn3

Hi everybody,

I’m trying to create a multiaction script. The script is divided into rollout_1, rollout_2, rollout_3, rollout_4, and each roll contains multiple buttons that have a different function, exmp button_01 random select object, button_02 random add material …

I would need, if possible, to create a final button that will do all the buttons.

rollout_01 – button_01
rollout_02 – button_02
– button_03
– button_04
– button_05
– button_06
rollout_03 – button_07
– button_08
– button_09
rollout_04 – final_Button

The ideal solution would be “on final_Button pressed do
rollout_01 button_01
rollout_02 random do button_02-06 – all buttons use
rollout_03 random do button_07-09 – all buttons use”
Is this a good procedure?
Thank you for your response.

14 Replies

not sure if it can help but you can declare the functions separately and call them one by one or alltogheter

try DestroyDialog temp catch()
rollout temp "do all roll"
(
button bt0 "delete objects" width:80 height:16 align:#center
button bt1 "create boxes"width:80 height:16 align:#center
button bt2 "random wire"width:80 height:16 align:#center
button bt3 "do all"width:80 height:30 align:#center

---functions declaration

fn deleteobjs = (delete objects)
	
fn createboxes = (
					delete objects
					local increment = 0
					for i=1 to 5 do (box lengthsegs:1 widthsegs:1 heightsegs:1 pos:[increment, 0, 0]
					increment += 40)
				)

fn randomwirecolor = (
					for o in objects do o.wirecolor=random black white
					)
				
---button function calls
	
on bt0 pressed do deleteobjs()
on bt1 pressed do createboxes()
on bt2 pressed do randomwirecolor()

on bt3 pressed do (deleteobjs();createboxes();randomwirecolor())
)
createdialog temp 100 300

Hi Conrad,
I’ve tried it and it works if it’s in the same rollout. If I fn add to last button in rollout 4, fn was not found “call needs fn or class got: ButtonControls: btn

try this

::myfunction()

with the :: before

It doesn’t work yet.
Can’t there be a bug in my rollout?
try DestryDialog newRolloutFloater catch ()
(
)
rf = newRolloutFloater 900 1000
addRollout a rf
addRollout b rf
addRollout c rf
addRollout d rf

I tried on btn pressed do btn1 (), on btn pressed do :: btn1 ()

your code is not going to work as it is

i guess you should look up the reference manual for how to make rollouts – subrollouts – floaters
and structure definitions if you need to go that way.

struct functioncontainer (
	fn bananas = (print "bananas"),
	fn apples = (print "Apples")
)



rollout a "Rollout A"
(
button a1 "a1"

on a1 pressed do functioncontainer.bananas()
	
on a resized val do (format "A: %\n" val)
)
--
rollout b "Rollout B"
(
button b1 "b1"

on b1 pressed do (functioncontainer.bananas();functioncontainer.apples())

on b resized val do (format "B: %\n" val)
)
--
rof=newrolloutfloater "test" 200 200
addrollout a rof
addrollout b rof
rof.size=[300,300]

here is an example patching up some reference manual code

Thanks for the answer, “struct” solved it all. So far, I’ve tried to find everything myself, but I’m starting with ms.

last question, is it possible to set random to fn?
exmp: on button pressed do (fn1 (); fn2 (), fn3 (), fn4 ()) — but fn1 () – still first and fn2 (), fn3 (), fn4 () will be random do:
variant 1 — (fn1 (); fn2 (), fn3 (), fn4 ())
variant 2 — (fn1 (); fn3 (), fn2 (), fn4 ())
variant 3 — (fn1 (); fn3 (), fn4 (), fn2 ())


(
	
	fn f1 = format "1\n" 
	fn f2 = format "2\n" 
	fn f3 = format "3\n" 
	fn f4 = format "4\n" 
	fn f5 = format "5\n"
	fn f6 = format "6\n"
	fn f7 = format "7\n"
	fn f8 = format "8\n"
		

	fn RunRandomOrder = 
	(
		local funcs = #( f2, f3, f4, f5, f6, f7, f8 )
		
		for i = funcs.count to 2 by -1 do
		(
			k = random 2 funcs.count 
			swap funcs[1] funcs[ k ] -- shuffle the array
		)
		
		f1()
		
		for func in funcs do func()
		
	)

	RunRandomOrder()

)

Hi Sergey, thank you for your time.
I believe your code is correct, but I have something else wrong. When the button is running, it cannot call fn. First fn from first rollout crush, if I cancel fn 1 the remainder fn will not do anything but will not write an error.

My scheme:
rollout 1
fn 1 (all code)
on btn_1 pressed to 1 () —— work ok

rollout 2
fn2 (all code)
fn3 (all code)
fn4 (all code)
on btn_2 pressed to 2 () —— work ok
on btn_3 pressed to 3 () —— work ok
on btn_4 pressed to 4 () —— work ok

I tried:
rollout 1
struct function container
(
fn 1 (all code)
)
on btn_1 pressed to functioncontainer1 () —— work ok


But the final button doesn’t see the way.
exmp: on FinalButon pressed to (functioncontainer.fn1 (), functioncontainer1.fn2 ()) — work ok


I think I should create:
rollout 1
struct function container
(all fn)
rollout 2
struct functioncontainer2
(all fn)
rollout 3
struct functioncontainer3
(all fn)
rollout 4
“Final button”

you need to post as least simplest example of the code that doesn;t work to get the help as there could be a lot of things that could go wrong terminating the execution.
Read about try catch blocks in the reference if you want your code to proceed execution. Maybe that will help

Page 1 / 2