Randomize Sliders

Hello, I've created a rollout with several sliders and a couple of buttons. I want To be able to press one of the buttons at the bottom of the rollout and generate a set of random values for the sliders. Is this possible? I've attached my script below to make it easier to see where I've gone wrong......many thanks

rollout slide "Riot Parameters"
(
slider slide "Political Pressure" range:[1,11,1] type:#integer ticks:10
label lbl "0%"
local lbltext = #("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%")
on slide changed val do lbl.text = lbltext[val]

slider slide2 "Social Pressure" range:[1,11,1] type:#integer ticks:10
label iki "0%"
local ikitext = #("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%")
on slide2 changed val do iki.text = ikitext[val]

slider slide3 "Racial Tension" range:[1,11,1] type:#integer ticks:10
label plp "0%"
local plptext = #("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%")
on slide3 changed val do plp.text = plptext[val]

slider slide4 "Local GDP%" range:[1,11,1] type:#integer ticks:10
label gdp "0%"
local gdptext = #("-5%", "-4%", "-3%", "-2%", "-1%", "0%", "1%", "2%", "3%", "4%", "5%")
on slide4 changed val do gdp.text = gdptext[val]

button GetRandom "Randomise Parameters"
(
on GetRandom pressed do
(

)

)

button GetRandomWeather "Generate Weather"
(
on GertRandomWeather pressed do
(

)

)
)

createdialog slide

Comments

Comment viewing options

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

try this

rollout slide "Riot Parameters"
(
	local lbltext = #("0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%")
	slider sld1 "Political Pressure" range:[1,11,1] type:#integer ticks:10
	label lbl "0%"
	slider sld2 "Social Pressure" range:[1,11,1] type:#integer ticks:10
	label iki "0%"	
	slider sld3 "Racial Tension" range:[1,11,1] type:#integer ticks:10
	label plp "0%"
	slider sld4 "Local GDP%" range:[1,11,1] type:#integer ticks:10
	label gdp "0%"
	button GetRandom "Randomise Parameters" width:120
	button GetRandomWeather "Generate Weather" width:120
	local slidersArr = #(sld1, sld2, sld3, sld4)
	local labelsArr = #(lbl, iki, plp, gdp)
 
	on sld1 changed val do lbl.text = lbltext[val]
	on sld2 changed val do iki.text = lbltext[val]
	on sld3 changed val do plp.text = lbltext[val]
	on sld4 changed val do gdp.text = lbltext[val]
	on GetRandom pressed do 
	(
		for i = 1 to slidersArr.count do 
		(
			val = random 1 11
			slidersArr[i].value = val
			labelsArr[i].text = lbltext[val]
		)
	)
	on GertRandomWeather pressed do
	(
 
	)
)
createdialog slide

barigazy

bporter88's picture

PERFECT! Thank you so much,

PERFECT! Thank you so much, works a treat

Comment viewing options

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