playMaker

Author Topic: Lots of 'if'/switch in a single FSM, or multiple simple FSMs?  (Read 1154 times)

frteae

  • Playmaker Newbie
  • *
  • Posts: 9
Lots of 'if'/switch in a single FSM, or multiple simple FSMs?
« on: September 19, 2016, 06:26:48 AM »
I have a bunch of light bulb switches, and other interactable objects.

When my player 'presses' a button, I want it to switch on/off a light, depending on which switch is pressed.

I currently have a 'last interacted with' variable that stores the last thing I've clicked on.

Would it be better performance to:
a) Have a simple FSM on each button checking it is the last item clicked each frame, and my game ending up with many FSM's; or
b) Have a 1 large FSM with multiple 'if's testing for each button in sequence every frame?

I use lightbulbs as an example, but I'll have various simple objects (switch on/off TV, switch on/off lights etc, with each button linked to an object)

Thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Lots of 'if'/switch in a single FSM, or multiple simple FSMs?
« Reply #1 on: September 19, 2016, 12:05:55 PM »
Hi,
I would use an int value to know which button was pressed last
so if you press button 1, do the bool switch and also do a set int value and set it to 1.
for button 2 set the int to 2 and so on, then you can use an int switch to get to the last button pressed, if you would add them to an array you could even go back several steps.