Attributes don't work??

20041842004184 Member Posts: 14
edited November -1 in Working with GS (Mac)
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!

Comments

  • BeyondtheTechBeyondtheTech Member Posts: 809
    Funny how I'm discovering a similar issue with my new game.

    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?
  • JackBQuickJackBQuick Member Posts: 524
    @2004184: When do you reset or change the value of ChangeColour or ChangeExample? What might have happened is that these values changed before the rule to add 10 to GameScore is implemented.
  • 20041842004184 Member Posts: 14
    When I click on a colour, the attribute ChangeColour changes into the number of the colour, so when red is clicked, ChangeColour becomes 1. The first fase of my example is grey, so the first actor needs to become grey. When grey is clicked in the colourpannel, ChangeColour becomes 8. If then the white actor is clicked, it changes into a grey image. At the same time, the example changes into a new image, this happens randomly. This by the attribute ChangeExample. When the white actor is clicked, ChangeExample picks a number randomly, and becomes the colour of the number. So when ChangeExample becomes red, so 1, the ChangeColour needs to be red too, so you need to click on the red colour so the ChangeColour becomes 1 too.
    Do you get it a bit more now? My explaining techniques are a bit bad..
  • JackBQuickJackBQuick Member Posts: 524
    There was a line you wrote which caught my attention: "At the same time, the example changes into a new image, this happens randomly."

    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?
  • 20041842004184 Member Posts: 14
    Thank you very very much for your response, but both things don't work.. The timer doesn't, and the ChangeColour = ChangeExample doesn't work eather.. Someone else got an idea what could be wrong? I'm pretty desperate!!
  • CatOnAKeyboardCatOnAKeyboard Member Posts: 39
    Are you using actor attributes or global attributes? I have noticed in the past that rules using actor attributes often don't work properly, but it can usually be fixed just by making all your attributes global...
  • 20041842004184 Member Posts: 14
    And global is a scene attribute instead of a game attribute? Or something different?
  • CatOnAKeyboardCatOnAKeyboard Member Posts: 39
    There are 3 kinds of attributes (variables) that you have access to: Game (Global) Attributes, Scene Attributes, and Actor Attributes. As I said before, using actor attributes can often cause problems, so it would be best to use Game Attributes for any variable that you plan to update frequently.
  • JackBQuickJackBQuick Member Posts: 524
    @2004184: I think that it may be a timing issue that you're experiencing. Since I'm new to GameSalad, I like to take the opportunity to figure out how to do things as much as I can -- it's the way I learn. I took your issue and tried it myself. Here are my results:

    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.
  • 20041842004184 Member Posts: 14
    Oh, thank you so much for your help! I checked out your game and it is indead very much alike my game.. But I don't really know what to do next, and on what I need to put a timer.. My rules look like the ones you used to create your colour-game, and I'm sure that those are all correct in my game because it worked before, when I didn't choose to pick the examples randomly. I keep trying but don't know for sure what to do!
  • JackBQuickJackBQuick Member Posts: 524
    At the place where you "pick the examples randomly", try putting in an "After" timer with a duration of 0.5 seconds. Then, drag the Change Attribute box where you "pick the examples randomly" into the body of this timer.

    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!
  • JackBQuickJackBQuick Member Posts: 524
    @2004184: Actually, I put everything into a timer and selected the Run to Completion checkbox -- this ensures that everything will run regardless of whether the initial conditions that satisfied the rule have changed.

    image
  • ckck Member Posts: 224
    I've been having a very similar problem (with a probably similar colour game).

    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....
  • ckck Member Posts: 224
    To update this:

    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.
  • CatOnAKeyboardCatOnAKeyboard Member Posts: 39
    Wow, that's one I haven't heard of before. Is there any chance that you can upload a version of your project that has only this one thing in it, for everyone to see? Because I'd like to see it happen! lol
  • ckck Member Posts: 224
    Yeah, well, I'm new to this, so it's probably some stupid error on my part. I just ripped a feature out of the game and it fixed everything. I'll look into finding a way to make a version to upload, once I finish the real one.
Sign In or Register to comment.