Multiple condition/attribute check
ryast
Member Posts: 145
Hey!
I'm a noob and just getting started building my test games to get a feel of GS.
Quick question, I have an attribute
"testGs" that is always equal to a number between 1 and 10
Do I have to have 10 rules that basically say:
game.testGs = 1
spawn yellow actor
game.testGs = 2
spawn blue actor
game.testGs = 3
spawn green actor
game.testGs = 4
spawn red actor
etc
Or am I doing it wrong? Is there an easier way of doing this? Because in my test case I have just 10 possible conditions, maybe in a future game there are 50 possible conditions...
Thanks! Sorry if my question is too noobie
Comments
Yes, that's right. It can be a pain doing that if you have multiple conditions. A solution is to only have one "color" actor that spawns and then stores the game.testGS in a self attribute. Based upon that self attribute value, it will change color and act accordingly. This way you can have one rule and one color actor. This saves you tons of time coding and messing with all of those variables.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Thanks for replying!
Do you have a link that explains the "self" attribute a little more, please?
"Self" attributes are actor attributes. GameSalad has "game" attributes that are essentially global variables, "scene" attributes limited to a specific scene, and "self" attributes limited to a specific actor. Some of the built-in actor attributes are self.Position.X, self.Size.Width, self.Time, and self.Rotation. Custom attributes can be added by clicking on the '+' button and then selecting an attribute type, such as integer.
The idea is that each actor can have its own attribute value. So if you have 5 enemies with a self.lives attribute set initially to 5 and each enemy has a rule that says When actor collides with [bullet actor], change attribute self.lives to self.lives-1 then when a particular actor collides with a bullet, it will reduce its self.lives attribute by one. But the other enemy actors will still be at 5 or whatever value they last had.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks for the explanation!
I did a bit of Java programming a long while back, but I'm coming from a PHP/Python background now and your reply does help a lot!