playMaker

Author Topic: Simple counter system[SOLVED]  (Read 1800 times)

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Simple counter system[SOLVED]
« on: March 09, 2021, 11:44:28 AM »
I have an FSM where my game character throws an object using Get Button Down.  Each time you press the button, the character throws the object.  When this FSM is activated, I want to limit the number of "throws" available, for example you can only throw 5 times and then you can't throw.  Any tips getting this setup?  I'm guessing it's pretty simple.  Thanks for any help.
« Last Edit: March 23, 2021, 08:52:36 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Simple counter system
« Reply #1 on: March 09, 2021, 12:34:41 PM »
Hi.
Each Throw, do a 'Int Add' to a variable and do a 'Int Compare' to check if a certain amount is reached.

to 'Reset' you can do a 'Set Int Value'

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Simple counter system
« Reply #2 on: March 10, 2021, 10:47:59 AM »
Awesome that is working for me.  Thanks.

tyresebro1

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Simple counter system
« Reply #3 on: March 11, 2021, 05:25:03 AM »
I am working on designing a Modular exponentiation entity which uses a modular multiplication component (which i previously designed and verified). Now the modular multiplication component has its own internal own FSM and has a latency of a certain number of clock cycles.

The Modular exponentiation entity has its own FSM. The design problem that i am facing is that i need to keep track of how many times i have multiplied the base (eg. M5 = MMMMM). I have an integer variable that counts the number of times multiplication has taken place and is then compared to the exponent to control the next state of the FSM. Now what would be the best of implementing such a counter inside an FSM?

The approaches that i have tried are creating a separate state just to increment the counter (this resulted in the increment of the counter several times where it was supposed to increment only once), having an if statement with the condition rising_edge(clk) to increment the counter inside the newly created state (which i have been told is a bad design practice).

Any help would be appreciated. Thanks Acrylic Dining Table Manufacturers
« Last Edit: March 12, 2021, 10:03:46 AM by tyresebro1 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Simple counter system
« Reply #4 on: March 11, 2021, 06:00:50 AM »
Hi.
Increasing an int in a separate state should normally not result in incrementing several times.

How / when are you incrementing.

There might be a unwanted loop going on or a multiple incrementing event.

Maybe show some images/video on your fsm setup.

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Simple counter system
« Reply #5 on: March 12, 2021, 11:24:51 AM »
I'm having an odd issue now where my "thrown item limit" is acting inconsistently.

As suggested I am using "Int Add" to a variable (Add value =1) and then "Int compare" to trigger an "empty" event after 5 thrown items are reached, and resetting to 0 using "Set Int Value."  I have a pickup item prefab that activates my Throw FSM, so when you collect it you are given 5 throws.

This is working fine except for the first time when starting my game when I collect the pickup item for some reason I can only throw 4 times.  Then when I collect the item again I can now throw 5 times and then continue throwing 5 times consistently each time I deplete to 0 and pick up the item again.

Any idea why I can only throw 4 times only at first when starting a new game and then it switches to the intended 5 times?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Simple counter system
« Reply #6 on: March 13, 2021, 12:15:52 AM »
Can you show the state, action setup.

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Simple counter system
« Reply #7 on: March 22, 2021, 11:01:35 AM »
Apologies for the delay.  Here is my setup.


wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Simple counter system
« Reply #8 on: March 22, 2021, 11:02:35 AM »
And my inventory controller.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Simple counter system
« Reply #9 on: March 22, 2021, 03:46:36 PM »
Hi. move the 'Int Add' into the Create Throwable Object state

but make sure its above the compare action

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Simple counter system
« Reply #10 on: March 22, 2021, 06:49:31 PM »
Awesome that solved it.  Thanks much!