Alternating through game states.
I created a test project to try to understand how change attribute and constrain attribute works.
I created a game attribute called mode and an actor.
In side the actor i have 3 rules.
rule 1: if mode=0 set mode to 1
rule 2: if mode=1 set mode to 2
rule 2: if mode=2 set mode to 0
I expected the mode to alternate between 0,1, and 2, but display text to show mode just shows 0 all the time.
Then I thought maybe it's alternating but not showing it, so I added
another rule: if mode=1 set counter = counter+1
but displaying counter only shows 1 and not increment as the program runs.
So then i tried something else.
another project.
and i added one rule.
rule 1: if mode=0 constrain attribute mode = mode + 1
I only expected mode to be set to 1 but displaying it shows that it continue to count upward non stop...
So my question is if i wanted use a mode as a state machine how would i make my project to alternate through values like 0,1,2 then back to 0,1,2 again...
I just started GameSalad like last week so i am really confused when it comes to distinguishing the difference between change attribute and constrain attribute.
I know that if I don't have a rule, and just use change attribute, that code will run once and never run again sort'a like initializing variables.
Please explain in details how i would go about controlling a variable like a state machine. Thanks in advance.
Comments
I'd avoid using non-GS terms like 'set', there is nothing in GameSalad called a 'set', or a 'set' behaviour, so people will have to guess what it could mean, the less guessing in a discussion like this the better, I'd try to stick to actual GS terms.
You can use modulus to cycle through a set of numbers.
For example, when touch is pressed change X to mod(X+1,3)
Change attribute will change something when the behaviour is encountered, so will trigger just once (unless you set it up so that something is forcing it to trigger repeatedly - like a every-1-second-timer or something like that).
Constrain attribute fires permanently, so on every processor cycle / frame, it will tick away constantly in the background.
thanks for the quick reply
mod wouldn't work for me mod would happen all the time which isn't what i want... What if i want to manually control the states from 0, 1 and 2 and only change state when a bunch of other conditions happen in program...like at some conditions i might want to jump from 2 to 1 instead of 2 to 0... how would i control something like that?
I call it a state machine because it has 3 states, at some point in time when the right condition(s) are met, i can just change it to any state i like depending on the conditions.
I read the documentation it says that (A) only happens once unless it is inside a rule that being is false then becomes true again, and that's exactly what i have Change Attribute inside rule(s) that are false/true at different times..but the code seem to only run once.
In what sense would it work all the time ?
You can do it in all sorts of ways, I'd personally use mod, but you could just set up a few rules depending on your needs.
What is '(A)' ?
does this mean i have to put my simple 3 rules inside a timer that fires let's say 0.1 second? seems odd but i'll try it and see.
(A) is any action that's what they described in documentation...like Change Attribute is an (A)
when i wrote set mode to 1, i meant change attribute mode to 1...i have 3 rules and they only run once it seems, when the documentation says that because they're inside rules they should happen whenever that rule condition is true.
Ah, I see, sorry I was confused, these are called 'actions', and yep, actions only happen once.
Does this help?
Yeah, i think i'll have a timer instead of a touch pressed because i need it to be automatic based on other conditions which aren't touches.
Thanks.