Notifications
Clear all

[Closed] Exchanging information between Floaters

Ok, here is an example script that i made just to show what i’m talking about.


global porcentagem = 0
global plbl = "0%"

rollout progress_roll "Progress"
(
	progressbar pb height:30 width:274 color:(color 0 255 0)
	label lbl "0%"
	
	on Progress_roll open do
	(
		pb.value = porcentagem
		lbl.text = plbl
	)
)

rollout create_roll "Create Boxes"
(
	button btn "Create Boxes" height:50
	spinner spn "Number" width:100 type:#integer range:[0,100000,0]
	
	on btn pressed do
	(
		for y=1.0 to spn.value do
		(
			global porcentagem = ((y/spn.value)*100)
			porc = porcentagem as integer
			global plbl = porc as string + "%"
			destroydialog progress_roll
			createdialog progress_roll 300 60
			newbox = Box()
		)
		destroydialog progress_roll
	)
)

myflo = newRolloutFloater "Create Boxes" 200 120
addrollout create_roll myflo

What i was trying to do is, when you click on a button, it opens a new Dialog with a progress bar, when the progress gets to 100% the dialog will automatcly close.

The script above works, but it is 2x slower then the same script without the new dialog. (It keeps closing and opening the dialog to update it).

I would like to know if there is an better way of doing this?

2 Replies

Originally posted by KaMe
[B]

The script above works, but it is 2x slower then the same script without the new dialog. (It keeps closing and opening the dialog to update it).

I would like to know if there is an better way of doing this? [/B]

–you don’t need these anymore:
–global porcentagem = 0
–global plbl = “0%”

rollout progress_roll “Progress”
(
progressbar pb height:30 width:274 color:(color 0 255 0)
label lbl “0%”
)

rollout create_roll “Create Boxes”
(
button btn “Create Boxes” height:50
spinner spn “Number” width:100 type:#integer range:[0,100000,0]

on btn pressed do
(
	createdialog progress_roll 300 60 --create once when starting
	for y=1 to spn.value do --don't need 1.0 here, see below
	(
		local porcentagem = 100.0*y/spn.value --because 100.0 is a Float, the result will be Float, too
		progress_roll.pb.value = porcentagem --assign directly to the value in the open dialog
		progress_roll.lbl.text = (porcentagem as integer) as string + "%" --assign the string using integer to the label
		newbox = Box() --create the box
		sleep 0.01 --wait a 1/100 second, otherwise the script is so fast 

–you would not see the progressbar with 100 boxes :o)
–remove the line to get max. speed!
)
destroydialog progress_roll –destroy when ready
)
)

myflo = newRolloutFloater “Create Boxes” 200 120
addrollout create_roll myflo

Some timing tests with the old and the new one:
(Using Dual Athlon MP 2800+, YMMV)

*Creating 1000 boxes with your script took 16.61 seconds.
*Creating 1000 boxes with the new one (without the 0.01 delay) took 1.844 seconds!

Bobo

Thanks Bobo
The script is much faster now :]