Radio Buttons - an informal competition for glory points only

DoctorMikeReddy

  • *
  • Posts: 180
I am still a bit of a n00b at all this scene v actor v unattached scripts stuff. After trying to just hack a radio button set of scripts, I gave up. Can some nice person create for me a set of scripts that would allow radio buttons (on and off animation) that when you click one, turns off all the rest and allows the scene to know which is selected. Bonus marks for allowing the user to determine a default on button. I am sure there are loads of ways of doing it, but learning from your different ways of implementation will teach me a lot about the best way to approach coding in Stencyl. Extra extra bonuses for using just code blocks and even more honour and glory for doing it in a way that my decades older brain can understand.

Hectate

  • *
  • Posts: 4643
This sounds like an interesting challenge, ideas are already flowing within the tumultuous environs of my imagination. We shall see...
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

mormord

  • Posts: 94
Please take a look at this:
http://www.stencyl.com/game/play/6657
If it is what you want, you can download this game from the Forge. Runs by the name Radio button example. There are only two behaviors one for the actor, one for the scene. The actor uses actor attributes, and the scene a custom block, but other than that, it's pretty simple (I think at least :) )

coleislazy

  • *
  • Posts: 2607
Mormord, you rascal, you beat me to the punch!

This is my version: http://www.stencyl.com/game/play/6658

It is simply an actor behavior. The actors default to group 0, but you can use actor customization in the scene designer to change groups. The last added button of each group becomes the default. Just check the attribute _stateIsOn for the buttons to see which is on (remember to check the group value as well, if you're using multiple groups).

Also on SF as Radio button.

mormord

  • Posts: 94
Five minutes :D
In the meantime, I don't see your example on Forge. Did you forget to make it public or I'm searching in the wrong place?

coleislazy

  • *
  • Posts: 2607
It is under "Actors". It has the behavior attached.

DoctorMikeReddy

  • *
  • Posts: 180
I am not worthy! Must come up with some more challenges. Thank you for helping an old man, who started coding with ASM on a 6502,but wait... that wasn't my first programming. I made my own computer from a bin full of electrical relays in the 70s. Ah, switches...

DoctorMikeReddy

  • *
  • Posts: 180
OK, I have played with them both. coleislazy (certainly isn't) has a really nice look and a simple mechanism for adding buttons. However the game example is a bit laggy with mouse tracking, and the debug console is complaining about a missing behaviour; this could just be coleislazy's specific example. mormod allows selection of the animation for on and off (a nice touch), has no errors in his example and the game does not lag.

There is a finesse about coleislazy defaulting to the last added, even if it means that there is some work done by every previously added button when a new one is added; this might cause framerate problems or a delay in screen refresh. mormod has a flag for default with a warning that you should only have one. However, I cannot see a way to trap this obvious if minor way for people to FU. An alternative approach is to not have any set and trap the error of null if it is necessary, or have the scene choose a default.

Having said that, this was how I approached it too; you can handhold programmers too much can't you. mormod's approach if EVERY button was chosen as default would result in just the same behaviour as coleislazy, because each new button would replace the previous one as the "selected"; the only side effect being that every button that had been chosen as default would appear to be on. A way round this would be for the default animation to be off for all buttons, then the scene to select a group member for each group add it, and switch the animation to on. The problem would be when to do that, and this would prevent dynamic addition of new buttons at run time.

It's a tough call. I'm going to say this is a draw, as each approach has something the other hasn't.

Hectate

  • *
  • Posts: 4643
Wow, I go and do some work for a living and look what happens.

Oh well, I guess that means I can do something else, hah!
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.