playMaker

Author Topic: Linking together multiple sliders?  (Read 2472 times)

Nerfgun

  • Playmaker Newbie
  • *
  • Posts: 2
Linking together multiple sliders?
« on: April 15, 2015, 05:02:24 PM »
Hi there, short time lurker, first time Playmaker here.

I'm trying to suss out the best method for linking together a bunch of (4.6/5.0 uGUI) slider controls, which are bound by a pool.

It's for a space game. So the example is, a Master Pool of 30 points, and up to 8 sliders that can draw from that pool, which can range ("take") from 4 to 8 points each.

I can figure out the specifics but I'm just not sure how I should approach the overall problem. I need to update the display of Master power in realtime as the user clicks, and I also need to stop if they ask for more Power than can be assigned.

I have it set now very simply to subtract any given amount from a slider from the main pool, but it goes into a loop. I realize I have to step through this to prevent it but as I'm just getting used to PM I'm not sure where "the loop" exactly is during Every Frame type actions. Or what sort of Action(s) I should be using to check for changes.

thanks folks. really loving PM so far, it is something I've been looking for for a very very long time.
« Last Edit: April 15, 2015, 05:04:12 PM by Nerfgun »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Linking together multiple sliders?
« Reply #1 on: April 16, 2015, 01:57:48 AM »
Hi,

 that's very tricky actually...

 typically, all sliders shoudl be slaved by a "Manager" fsm, and you only communicate via this manager.

 everytime the user moves a slider, you'll be sending the new slider value to the manager, and the manager will do the math and update all sliders.

now the trouble comes when the user is dragging too much, you'll enter an infinite loop, the user drags 1 unit more, the manager corrects it, which means the slider sends again an update, etc etc.

typically, sliders should send an update of their value to the manager only if you detect a user interact, that will solve all sliders but th eone the user is interacting.

I would try the following. the slider you drag is only an indicator, and the real value of the slider is shown on a text field, so when the user slides too much, it's ok, you don't update the slider itself, but just the text field showing the value, that can be different from the slider value. when the user release the slider, you adjust the slider to reflect the true value from the manager.

 this way you'll have a chance to avoid infinite looping. So in short, update everything back but the slider the user is interacting on, and adjust that slider when interaction ends ( jumping back if the user was off limits)

 two way bindings is unfortunatly a nightmare in Unity, I whish they inspired from Adobe Flex, which has incredible power on that front... oh well... )

 Bye,

 Jean

Nerfgun

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Linking together multiple sliders?
« Reply #2 on: April 16, 2015, 07:46:43 AM »
Thanks very much jeanfabre. That helps quite a lot.

I started creating an EnergyManager gameobject last night to do pretty much what you have described here (so I was on the right track). It doesn't work yet but I have the general idea. The thing I'm still not sure about is how I'm going to limit the addition of energy to a subsystem *right away* as the user is dragging. I don't want a behaviour where a user assigns energy that isn't available mid-action (i.e. tries to drag in 6 points when only 3 are available from the pool) and has it 'snap back' upon mouseup or w/e. But I think I will try and get the basic math working first. I think my advantage is that you will only really be able to manipulate one slider at a time, and the other subsystem slides don't ever have to move in response to each other; only the master energy meter does.

OK thanks. I will report back with whatever I manage.

by the way here is an image that somewhat conveys what I am trying to do (ignore count states of dots/label at bottom)... it's the lower left quadrant of my screen:

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Linking together multiple sliders?
« Reply #3 on: April 16, 2015, 01:15:23 PM »
Hi,

 Yeah, the way to do this would be:

 the slider the user is controlling is only sending the expected value to the manager, it's never controlled by the manager, and then the visual feedback of this slider is actually another slider ( or graphics), that then represents the only possible values, regardless of how off limits the user is dragging.

 So, separate the visual feedback from the USer interaction slider itself and you'll be on a simple path to make this system. Don't try to do both a slider and a "meter" acting both as the input and output.


 Bye,

 Jean