Randomizer on 3 Grouped buttons, How?
-
It's a good start but there are a few problems.
1: I said forget about buttons. Just
Console.print()
in on init.
2: Your function is generating numbers between 0 and 3, you need 0 and 2This is all that was needed
const randomValue = Math.randInt(0, 3); Console.print(randomValue);
Since you're addicted to buttons let's move on to them :p
Add your 4 buttons, put the 3 you want to be random into an array. In the callback for the other button generate a random number between 0 and 2, like you did in your last snippet, and output it to the console.
-
@d-healey Haha :) Sir!!!
-
@d-healey No Idea,can't do it by myself :)
-
@Natan Yes you can, one step at a time. You're not by yourself, I'm here :D
Can you create an array?
Can you create a button?
Can you put a reference to the button into the array? -
@d-healey
I'm still here:Content.makeFrontInterface(600, 500); const randomValue = Math.randInt(0, 3); Console.print(randomValue); const var Btns = [Content.getComponent("Button3"), Content.getComponent("Button2"), Content.getComponent("Button1")]; inline function onRandITControl(component, value) { }; Content.getComponent("RandIT").setControlCallback(onRandITControl);
-
Perfect. Now move the
randomValue
inside the button's callback function, you'll need to use alocal
variable instead of aconst
.You can use the random value as the
Btns
array index to turn on one of the buttons. -
@d-healey is this correct?
Content.makeFrontInterface(600, 500); const randomValue = Math.randInt(0, 3); Console.print(randomValue); const var Btns = [Content.getComponent("Button3"), Content.getComponent("Button2"), Content.getComponent("Button1")]; inline function onRandITControl(component, value) { local idx = buttons.indexOf(component); }; Content.getComponent("RandIT").setControlCallback(onRandITControl);
-
@Natan Not even close :p
Move the
randomValue
stuff inside the button's callback. You'll need to use a local variable instead of a const. You can delete theConsole.print()
we don't need that now. -
@d-healey Lol
Content.makeFrontInterface(600, 500); const var Btns = [Content.getComponent("Button3"), Content.getComponent("Button2"), Content.getComponent("Button1")]; inline function onRandITControl(component, value) { local randomValue = Math.randInt(0, 3); Console.print(randomValue); }; Content.getComponent("RandIT").setControlCallback(onRandITControl);
-
Now we're getting somewhere!
We don't need
Console.print()
any more, that was just for testing the random value which we know works now.Do you know how to turn a button on or off by changing its value?
-
@d-healey Yeah, I Guess I'm So Close :)
Wait Sir -
@d-healey Haha, That Was A Real Challenge, And Yep This is it :)
Content.makeFrontInterface(600, 500); const var Btns = [Content.getComponent("Button3"), Content.getComponent("Button2"), Content.getComponent("Button1")]; inline function onRandITControl(component, value) { local randomValue = Math.randInt(0, 3); Console.print(randomValue); if (value == 1) { Btns[randomValue].setValue(1); } }; Content.getComponent("RandIT").setControlCallback(onRandITControl);
-
Yeah looks like you got it! Well done!
-
@d-healey :) Haha Yessir :)
Thanks You Dear David, True Legend :) -
@Natan You did it, not me. I just nudged you :p
-
@d-healey Thanks for the help, You're a great guy :)
-
@d-healey Just trying this out. What if I wanted only one of the buttons to be on at a time? Like a radio group. I can get them to go on and off randomly, but not like a radio group...
-
@DanH Check out my tabbed interfaces video.
-
@d-healey ah yes of course :) I'm already using it!
-
@d-healey Ok I am failing miserably at trying to combine these two scripts