Changing States / Finite State Machine

thatoneguy117thatoneguy117 Member Posts: 31
edited November -1 in Working with GS (Mac)
Hey guys! I've just started using GS and I think its awesome! I've been lurking for a bit and I just created my account and this is my first post!

Well, anyway, basically I have a couple of states controlled by changing a attribute.

I have an object that passes over 240 and it changes the attribute to 2

When it = 2 it moves to the object

When its under 240 it changes it to 1

When it = 1 it repels

I have a couple of other ones, but thats the main idea.

Basically I want to know how I can repeat these commands. When it = 1 or 2 it works fine, but once. I would like to know how to make it so when its always above 240 how I can run the command multiple times. Like run it every 3 seconds or something like that. I've been stuck on this for AWHILE so any help would be greatly appreciated thanks!

ThatOneGuy

Comments

  • thatoneguy117thatoneguy117 Member Posts: 31
    Anybody?
  • thatoneguy117thatoneguy117 Member Posts: 31
    Anybody???
  • Rob2Rob2 Member Posts: 2,402
    have you not thought about using a timer behaviour?
  • thatoneguy117thatoneguy117 Member Posts: 31
    I tried doing that.

    I had when attribute = 1

    every 3 s -> move to

    and I had every 3 sec when attribute = 1 -> move to, but that didn't work either.

    Literally it just didn't do anything.
  • chosenonestudioschosenonestudios Member Posts: 1,714
  • thatoneguy117thatoneguy117 Member Posts: 31
    scitunes said:
    http://gamesalad.com/game/play/76893

    Thanks Scitunes, I'll check it out.
  • thatoneguy117thatoneguy117 Member Posts: 31
    For my game I need to control whats going on and I have more than 2 states.

    Also the second actor that actually uses these commands below 240 and above 240 doesn't use them all the time.

    But basically I'm just asking once a attribute is active how can I continue to use these commands.

    Example: when attribute is above 240 move to, but move to will only work once as the attribute is active. It will work again after the attribute is flipped off and turned back on, but how can I make it so it will continually run every couple of seconds as the attribute command is true?
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    create an integer attribute called switch set it to 0

    Timer Every Blah seconds
    change self.switch to (self.switch+1)%2

    This will cause it to alternate between 0 and 1

    Then have a rule

    When self.switch = 0
    Do blah blah blah
    Otherwise
    Do blah blah blah
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    You can give it a state 0 that it is not moving or has finished completing its task. And the rule that checks which state to send it to, have those also check if the state is 0 and change the state to something else.
  • thatoneguy117thatoneguy117 Member Posts: 31
    CodeMonkey said:
    You can give it a state 0 that it is not moving or has finished completing its task. And the rule that checks which state to send it to, have those also check if the state is 0 and change the state to something else.

    So after it finished its task change it to state 0?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    yep. though you would need to decide how it knows when that task is done.
  • thatoneguy117thatoneguy117 Member Posts: 31
    Thanks CodeMonkey, I'll check it out
  • thatoneguy117thatoneguy117 Member Posts: 31
    Ugh, CodeMonkey I can't get this to work at all. I might have misunderstood you though. Could you maybe go into more detail? Could anybody else help me with this?
  • thatoneguy117thatoneguy117 Member Posts: 31
  • thatoneguy117thatoneguy117 Member Posts: 31
    Anybody?
  • amigoniamigoni Member Posts: 78
    Hi,
    I had a similar problem with one of my games.
    I created an integer called flying state within the actor. I then had a set of rules that governed the behaviour of 6 different flying states. For example
    State 0 - Don't Move
    State 1 - Move Down
    State 2 - Move Up
    State 4 - Move in a Wave
    etc.

    Each of these states was a rule that would have as one of the conditions Flying State = the corrisponding flying state number.

    So for example I had my character move down as State 1. Once it touched the ground I would have a rule to change the flying state to 2 which would make it move up. Then in flying state 2 I had a rule with a timer that after 1 second it would change the flying state to 3 so move in a wave.

    Hope it helps
  • amigoniamigoni Member Posts: 78
    Hi,
    I had a similar problem with one of my games.
    I created an integer called flying state within the actor. I then had a set of rules that governed the behaviour of 6 different flying states. For example
    State 0 - Don't Move
    State 1 - Move Down
    State 2 - Move Up
    State 3 - Move in a Wave
    etc.

    Each of these states was a rule that would have as one of the conditions Flying State = the corrisponding flying state number.

    So for example I had my character move down as State 1. Once it touched the ground I would have a rule to change the flying state to 2 which would make it move up. Then in flying state 2 I had a rule with a timer that after 1 second it would change the flying state to 3 so move in a wave.

    Hope it helps
  • thatoneguy117thatoneguy117 Member Posts: 31
    Hey, thanks amigoni. Thats how I have mine set up to except I can't have it changing states preset. I need it to be dynamic. Any other suggestions? You or anybody else?
  • amigoniamigoni Member Posts: 78
    Do you mean that you want it to change states randomly? If so you need a random generator separate from the actor.
  • thatoneguy117thatoneguy117 Member Posts: 31
    amigoni said:
    Do you mean that you want it to change states randomly? If so you need a random generator separate from the actor.

    Sorry, what I mean is I need it to change based off a set of commands I.E.

    When attribute is above 240 change to state 1
    When attribute is below 240 change to state 2
    Etc.

    The thing is I need it to be able to run the commands multiple times without having to change the attribute.

    CodeMonkey Helped me with this and almost got it working.

    I got it so it would change to state 0 and reload back to the other ones and this worked GREAT.

    One problem though after the object that is chasing (state 1) change x and y coordinates via change attribute it no longer worked. So I need something that takes this into consideration with the other commands also, Thanks.
  • amigoniamigoni Member Posts: 78
    Sorry but I need something more concrete to help you what are the parameters?

    It seems that all you have to do is have a rule.

    if is above 240 change attribute self.state to 1
    otherwise change attribute self.state to 2
  • thatoneguy117thatoneguy117 Member Posts: 31
    Thats what I did, but the problem is if it stays above 240 for awhile that state will only work once, unless you change the state again, but I need it to work multiple times.
  • amigoniamigoni Member Posts: 78
    It makes no sense. Why would it only work once and why is it time dependent. If you can explain it another way or in more detail I might be able to help you.

    It should make no difference how long it stays about 240.
  • thatoneguy117thatoneguy117 Member Posts: 31
    I'm not sure why, but codemonkey obviously knows this too. That's why he told me too clear out the states of the object.

    Sorry, maybe I'm explaining this really bad, but I'll post some images when I get back to my house. I should be back in a hour and twenty.

    Again, thanks for your help
Sign In or Register to comment.