Changing States / Finite State Machine
thatoneguy117
Member Posts: 31
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
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
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.
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?
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
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
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
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.
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
It should make no difference how long it stays about 240.
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