Attribute Condition
Hi all,
I'm new to GameSalad and have been messing around with it for a little while, but I don't quite understand the Attribute Condition. When exactly does it run? I kind of thought it would be listening all the time and thus would run whenever the condition was met, but it doesn't seem to be working that way (at least from what I can tell).
In case it helps answer my question, I'll give some specifics as to what I am trying to use it for.
- I have a table I want to use to store enemies current positions.
- I couldn't find a way to constrain a table cell to a value, so I tried the following rules on my enemy actor who is in the first row, where column 1 in the table is the X position as a real and column 2 is the Y position as a real:
- if self.position.x != tableCellValue(game.Enemies, 1, 1)
- Change Table Value
- Table: Enemies
- Row: 1
- Column: 1
- Value: self.position.x
- Save Table
- Table: Enemies
- if self.position.y != tableCellValue(game.Enemies, 1, 2)
- Change Table Value
- Table: Enemies
- Row: 1
- Column: 2
- Value: self.position.y
- Save Table
- Table: Enemies
The reason I asked above about the Attribute Condition, is that I put a spawn actor in these conditions just to see if they were running and no actors are spawning, so it seems like it isn't being run continuously like I thought (in fact it doesn't seem to be run at all!).
So I guess I have two questions:
1. When does the Attribute Condition get run?
2. Does anyone know a way to constrain a table cell to an attribute?
Edit: hmm the formatting didn't seem to work, sorry about that.
I'm new to GameSalad and have been messing around with it for a little while, but I don't quite understand the Attribute Condition. When exactly does it run? I kind of thought it would be listening all the time and thus would run whenever the condition was met, but it doesn't seem to be working that way (at least from what I can tell).
In case it helps answer my question, I'll give some specifics as to what I am trying to use it for.
- I have a table I want to use to store enemies current positions.
- I couldn't find a way to constrain a table cell to a value, so I tried the following rules on my enemy actor who is in the first row, where column 1 in the table is the X position as a real and column 2 is the Y position as a real:
- if self.position.x != tableCellValue(game.Enemies, 1, 1)
- Change Table Value
- Table: Enemies
- Row: 1
- Column: 1
- Value: self.position.x
- Save Table
- Table: Enemies
- if self.position.y != tableCellValue(game.Enemies, 1, 2)
- Change Table Value
- Table: Enemies
- Row: 1
- Column: 2
- Value: self.position.y
- Save Table
- Table: Enemies
The reason I asked above about the Attribute Condition, is that I put a spawn actor in these conditions just to see if they were running and no actors are spawning, so it seems like it isn't being run continuously like I thought (in fact it doesn't seem to be run at all!).
So I guess I have two questions:
1. When does the Attribute Condition get run?
2. Does anyone know a way to constrain a table cell to an attribute?
Edit: hmm the formatting didn't seem to work, sorry about that.
Best Answer
-
tatiang Posts: 11,949
You can't constrain a table value using a Constrain Attribute command, but you can use a timer to effectively constrain table values. To do that, you would place a Change Table Value behavior inside of an Every 0 seconds timer.
You're asking about something you're calling the "Attribute Condition." This is generally what we refer to as a "Rule." A rule might be When attribute game.Time>5... [do something]. That rule will trigger and become active when game.Time first exceeds 5 (seconds). It won't trigger again after that because the rule hasn't changed status from false to true. It became true and has stayed true. If game.Time gets reset, then the rule will trigger again when the value exceeds 5.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
2.) If you are doing a constrain, I am pretty positive that is a variable that you need to hold either globally, or within an actor, and can't be saved in a table constantly.
@tatiang I didn't realize you could do a Timer for every 0 seconds, I'll definitely give that a look, thanks! Is there a performance hit in doing this that I should worry about? Or something else I might not know that should worry about in doing this?
For the rules, if the rule is true from the beginning, will it never get run? Or will it get run once? The reason I ask this is that my rule was to check if my actors position was the same as the tables position, and if they were not the same, to change the table value to be the same. I was hoping to emulate the constrain attribute for a table cell in this way, but it wasn't working for me and even if the solution of using a Timer every 0 seconds works, I'd still like to understand why it wasn't working.
Thank you both for the answers, as soon as I give this a try I'll mark this as answered.
Yes, a rule that is true at the get go will run once.
Can you explain what you're doing from a big picture view? Are you trying to keep an actor in one place? Trying to snap an actor to a grid? Trying to keep two actors together? If I know that, I can suggest a best practice regarding tables and/or constrains.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Somewhat big picture: I'm trying to find a way to make it so when an Enemy Actor collides with a Range Actor the Enemy Actor will know where to shoot (it's actually a kind of reverse tower defense). And I'm trying to find a way to do this that will scale easily with however many Enemy Actors and Range Actors I want to make.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
If you don't mind, after messing with this some and incorporating it into my game, I'm running into another problem now. First I'll explain a little about how my game differs from the demo you made.
In the game the actors that move are the Enemy actors. The stationary actors are the Turret actors. The Turret actors have a Range actor around them and when an Enemy actor is within that Range the Enemy actor fires a Bullet actor at the Turret (as opposed to the Turret firing at the Enemy).
Okay, now for the issue. I can't figure out how I can have multiple Enemy actors firing at different Turret actors. Here's an example scenario of what I mean:
Let E1, E2, and E3 be instances of Enemy.
Let T1 and T2 be different instances of Turret.
Let R1 and R2 be different instances of Range, connected to their respective turrets.
Now, if E1 and E2 overlap with R1 and E3 overlaps with R2, E1 and E2 should shoot at T1, and E3 should shoot at T2.
The closest I've come to solving this is to have another table where the position a Bullet is supposed to fly to is stored in the columns 1 and 2. Then, when an Enemy overlaps with a Range, the Enemy actor will spawn a Bullet actor. The Range actor will set the position in the table, which is kept track of by a Game Attribute BulletRow, to be its center (since it's the same as its respective Turret actors center). The spawned bullet actor will then change its own Row attribute to be the BulletRow attribute, increment the BulletRow attribute, and then move to the position in table at the specified Row. The problem with this is if two Enemy actors overlap separate Range actors at the same time, or even close to the same time, there is the possibility that the Row attributes in the separate Bullet instances will get set incorrectly, and thus the Bullet instances will go towards the wrong Turret.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User