How can I have an attribute loop between 3 numbers?
BenMakesGames
Member Posts: 85
If I have a change attribute function that reads, for example, as follows:
Change Attribute "TrafficLight.Attribute" to ("TrafficLight.Attribute+1")#3
it will Loop the values 0 1 2(because of the applied #3)
Does anyone know how to have it loop the values 1 2 3 instead of 0 1 2?
Comments
this mite work, try it out.
set your trafficlight attribute to 1
then if you want the attribute to loop like youve mentioned do.
timer, every 0.1
change attribute "trafficlight.attribute" to ("trafficlight.attribute"+1)%3
GSINVENTION FREE TEMPLATES
You're correct in noting that the mod(,3) aka %3 function results in values of 0, 1, or 2. To return values of 1, 2, 3, you just add one to the mod result: attribute%3+1 or mod(attribute,3)+1.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
If you look at the output of any equation as nothing more magical than a number, a question like how can I have 1,2,3 instead of 0,1,2 should be self-explanatory (as others have pointed out if you want 0,1,2 to become 1,2,3 simply add 1 to the value).
So you got me thinking, because here in europe the traffic lights go yellow before turning green, i.e. green, yellow, red, yellow, green, yellow, ... (I think you notice a pattern?)
so I had to try and flipflop through a number series of 1,2,3,2,1,2,3
might also be usefull for a state machine
("trafficlight.attribute" mod 4)+floor((("trafficlight.attribute"-1) mod 4) / 3) * 2
Just for fun, can someone make this kind of cycle generic for any cycle length using a triangular waveform function?
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch nice! That could also be used for a waypoint actor that starts at position 1 (table x/y values), then moves to position 2, then to position 3, back to 2, back to 1, rinse and repeat.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
exactly what im working on. Thanks for the answer everybody. Ill get onto adding it in shortly.
I posted my generic solution for counting any odd sequence of numbers up and down and up again in the following tread
http://forums.gamesalad.com/discussion/52494/spare-code-dump-it-here/p16
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
For 1,2,3,2,1,2,3,2,1 you can try:
abs(mod( self.Time ,4)-2)+1
For 1,2,3,4,3,2,1,2,3,4,3,2,1 try:
abs(mod( self.Time ,6)-3)+1
For 1,2,3,4,5,4,3,2,1,2,3,4,5 try:
abs(mod( self.Time ,8)-4)+1
For 1,2,3,4,5,6,5,4,3,2,1,2,3,4,5,6 try:
abs(mod( self.Time ,10)-5)+1
See the pattern?
By the way, you don't necessarily need to use self.Time. Its just a useful built-in counter. You can use any means you want to create an incrementing counter.