Scene attributes
cgaliano
Member, PRO Posts: 21
This thing of not being able to refer to an scene attribute from an actor's prototype script (only from the instance's one, apparently) is pretty annoying as I cannot setup a rule that is valid for all scenes unless I copy it on every single scene. How do you guys work around this?
Comments
I typically never create Scene Attributes, usually use Game or Actor Level only. The only time I need to create an instance actor is if I need to access a pre-defined Scene Attribute like the camera settings.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
how do you then deal with counters and things that build up within a scene, but are to be reset at the beginning of every new scene? say for example you need to kill a number of enemies on every scene, and that number is different for every scene. You want to count how many do u kill on every scene and whether that number reaches the maximum for that scene. How can u do that with a unique attribute at the game level?
You should see three tabs if you're working with the windows creator: Game; Scene; Actor.
In the Game tab, just click the plus icon to create a game level attribute.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
Same here.
You reset them manually with an actor in each scene that has a bunch of Change Attribute behaviors such as Change Attribute game.enemyCount to 0.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It's important that Scene attributes cannot be accessed from scenes other than the one they reside in. If they could be, they would be no different from Game attributes. As the others have said, you should be resetting game attributes between scenes to get the result you want. Simply relying on scene attributes that you ignore once you're done with them would probably lead to problems down the road - for example, what if they reply the game? Each scene attribute will still hold the value you put in there last time. If that's what you desire, then just make a separate game attribute for each scene.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@tatiang , the number of enemies to be killed is to set for each scene (for example scene 1 has 5 guys to kill, scene 2 has 10, scene 3 has 20 and so on). I would like to build a logic, common for all scenes so I dont have to keep repeating it, that checks the number of enemies killed in that one scene against the set target for that one scene. I can reset the number of enemies killed in every scene to 0 at the start of it, but how do I know what is the target for that scene if it is different for every scene? if would be nice to refer to that scene attribute with one single logic that works for all scenes.
hi @Armelline . Creating a separate game attribute for each scene would work, but that would defeat the purpose of a scene attribute that always has the same name (so you can refer to it from every scene without having to change your logic) as opposed to have to refer to a different attribute name depending on the scene you are on.
If the number of enemies per level follows some sort of mathematical pattern, then all you have to do is figure out the math.
Let's say your base is 5 enemies for level 1, right?
Start with this formula...
game.enemies = game.base_enemies * game.level
Adjust as necessary.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
it should not have to follow any pattern necessarily. I just want to be able to set whatever number I want per scene and have one only logic that works for all occasions. I really think that should be the purpose of the scene attributes but I think that it is not working well in GS.
In that case you may want a "spawner" actor (or something similar) with a self attribute, probably called "enemies." You can unlock this attribute without having to unlock the rest of the actor. So all you have to do is change the value.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
Here's a quick demo.
As you can see, the prototype of Actor 1 has an attribute called "enemies" with a value of 0.
Each scene has this exact same actor with the value of "enemies" changed.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
You need to think of a scene more as an actor. Scene attributes are like self attributes for the scene. They aren't intended to be interacted with in the way you want. I understand what you're wanting to do, but you're only going to save 1 behaviour per scene doing it that way (were it possible). What you want is basically for GameSalad to do that extra work in the background, which it doesn't do in this instance.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@cgaliano like @Summation, demo I usually have a 'game controller' actor on each scene that I use to keep track of score, enemies, etc. This controller actor uses Actor Attributes that can be set and re-set as needed on each scene.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Well, thanks all for your comments. I think that you all have found ways to make this work and I will definitely follow your lead and do it in the same way but.... I still think that this is a bit of a weakness of GS. The number of enemies to be killed per scene is, if you think in plain English, an attribute or a property of the scene itself, and it should be referrable by any other object interacting with that scene, whether the reference is in the prototype or in an instance of that actor. It is not the property of a hidden actor that you are forced to create just to make this work, an extra actor that wouldn't need to exist if it wasn't for this very reason.
Appreciate all of your input in any case!
If you don't have a mathematical pattern then you would use a table where each row holds the value for that level (e.g. row 1 for level 1, row 2 for level 2, etc.). Wherever you need to use the value, insert tableCellValue(tableName,game.level,1) assuming the values are in the first column of the table. Then in an actor on each scene Change Attribute game.level to game.level+1.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I agree with cgaliano. The scene attributes should be accessible to prototypes while their scope remains local to the scene. All these workarounds are kludges.