Attributes don't work??
2004184
Member Posts: 14
Hi there,
I have a question concerning my game, but I'm not quite sure what's wrong..
I have these attributes: ChangeColour, GameScore and ChangeExample.
The goal in my game is to colour an actor. You have to do this by clicking the colour asked in the example, and then click on the actor. This works.
The only thing that's going wrong is that when the actor is coloured correctly, the score has to add up with 10 points.
In my example-actor, I created 9 different colouractors. The example changes when you click on the to-be-coloured actors, right colour selected or not.
The actors to-be-coloured contain a rule which says:
when touch is pressed, ChangeExample to random(1,9),
so the example is picked randomly. I can't predict what the colour of the example is going to be, so the score is quite difficult to fix.
I did it this way.
A rule with:
when ChangeColour = 1
when ChangeExample = 1
change attribute GameScore to GameScore + 10.
and then also with 2, 3, 4 etc, up to 9 (because there are 9 colours).
Then, when tried in the preview mode, it SOMETIMES works. Sometimes when the correct colour is picked, the score adds up with 10.. Does someone know what I have done wrong?
Thanks in advance, I'm waiting for an answer!
I have a question concerning my game, but I'm not quite sure what's wrong..
I have these attributes: ChangeColour, GameScore and ChangeExample.
The goal in my game is to colour an actor. You have to do this by clicking the colour asked in the example, and then click on the actor. This works.
The only thing that's going wrong is that when the actor is coloured correctly, the score has to add up with 10 points.
In my example-actor, I created 9 different colouractors. The example changes when you click on the to-be-coloured actors, right colour selected or not.
The actors to-be-coloured contain a rule which says:
when touch is pressed, ChangeExample to random(1,9),
so the example is picked randomly. I can't predict what the colour of the example is going to be, so the score is quite difficult to fix.
I did it this way.
A rule with:
when ChangeColour = 1
when ChangeExample = 1
change attribute GameScore to GameScore + 10.
and then also with 2, 3, 4 etc, up to 9 (because there are 9 colours).
Then, when tried in the preview mode, it SOMETIMES works. Sometimes when the correct colour is picked, the score adds up with 10.. Does someone know what I have done wrong?
Thanks in advance, I'm waiting for an answer!
Comments
I have an energy bar Actor that's made of ten different images (bar_#_png).
This is what I'm doing:
`
Constrain Attribute: self.Actual = floor(game.EnergyLevel*0.1)*10
If self.Displayed =/= self.Actual
... Change Attribute: self.Displayed = self.Actual
... Change Attribute: self.Image = game.FilenamePrefix .. self.Displayed .. game.FilenameSuffix
`
In the game, it's supposed to update when the difference between the displayed image and the actual value is greater than 10. But, it doesn't update because it doesn't pass the IF test after the first run.
However, if I change the line to `... Constrain Attribute: self.Displayed = self.Actual` it updates as it should. Given any performance hit when using a Constrain vs. Change, I don't think I should be too bad since it's inside an IF statement.
It's just more concerning why it doesn't change the value.
Gendai folk, any ideas?
Do you get it a bit more now? My explaining techniques are a bit bad..
I would insert a timer so that this happens after, say, 0.5 seconds -- you want to give your game a bit of time to evaluate all 9 rules which compares ChangeColour to ChangeExample before the value of ChangeExample changes. If 0.5 seconds doesn't work, try 1 second. However, you would want to test this and set it to the least amount of time possible and still have it work.
One more thing. If I'm reading this correctly -- and, because I'm tired and I'm having difficulty thinking, I might not be -- you have 9 rules that go:
when ChangeColour = 1 and
when ChangeExample = 1
then do...
when ChangeColour = 2 and
when ChangeExample = 2
then do...
etc.
Is there a way to compress this to ChangeColour = ChangeExample? Maybe by making ChangeExample into a global game attribute?
http://gamesalad.com/game/play/51254
I know that this isn't exactly what you had in mind but I think it has a lot of elements of your game that you described. Please feel free to download it and check out the code. (I think this works about 99% of the time.)
I found that I couldn't get away from creating switches and timers to make sure that events happened in the order that I want them to.
Working with GameSalad, be aware that many things can happen at the same time. If process #2 depends on the results of process #1, make sure that process #1 finishes before process #2 starts.
This has been discussed in the forums under various forms and the developers of GameSalad are certainly aware of this issue:
http://gamesalad.com/forums/topic.php?id=3717
Best of luck!
P.S. The only actors that you can't see are the X's that indicate the player's choices. I wanted them offscreen at the start of the game so I positioned them at x=500 and y=500. (Not my best decision; and, I couldn't undo it afterwards.) When an actor is pressed, they position themselves over the actor that was pressed.
You want the randomly generated examples to be the absolute last thing that happens; you want it to happen after you increase the score by 10. This is the reason for the timer.
If this works, try decreasing the timer from 0.5 seconds to something shorter. You want this timer to be as short as possible while still allowing your game to work properly. This takes a bit of testing.
Good luck!
Based on the colours pressed, the number of them, and the order in which they are pressed, an Attribute (color) is set to: blank, red, blue, etc.
When a button/actor is pressed, an actor is spawned and a sound is played, based on the state of the Attribute (color).
The correct sound always plays, but the wrong actor is often spawned.
A couple of actors (orange and purple) kept spawning when they weren't supposed to. Specifically, once they had spawned, it was as though they were hanging around in memory, and wouldn't allow another actor to spawn. In fact, the right actor was spawning, but then orange or purple were spawning over the top of them.
To explain:
I followed your advice, JBQ, and placed the spawn actor Action in a timer to occur after 1 second. I then learned that once either the purple or orange actors had been spawned, even after they had been destroyed, they were then spawning when other actors should.
To be clear, after orange or purple were spawned once, they always spawned with the spawn actor command. I learned this because after putting in the 1 second wait, when I spawned an actor, the orange or purple actor would spawn, and then the appropriate actor would spawn over them one second later. Before putting in the wait, the appropriate actor had been spawning, but then the rogue orange or purple were spawning on top of them.
I'm frustrated six ways from Sunday, as this doesn't look fixable....
I tried duplicating the orange and purple graphics outside of GameSalad, importing those graphics, pasting the code from the previous orange and purple actors into the new actors, and changing all references in the game from the old actors to the new ones.
The one thing I didn't change in the new actors was to leave movable checked.
So I test the game, and the old actors are still pasting ... BEHIND the new actors. I know because the new actors fell away, being subject to gravity.