How to change image using "change attribute"

Mr HansonMr Hanson Member Posts: 94
edited October 2012 in Working with GS (Mac)
Good day all

How would I change the image of my my actor using change attribute function. I have another attribute which says a number, I then want my actor to change to "number".png.
I think it's simple because most people do but I don't know what to do here

All the best
JonApp

Comments

  • carlblanchetcarlblanchet Member Posts: 755
    To change an actor's image using the change attribute behaviour you do this:
    -Change Attribute-
    Self.Image to "NameOfImage"

    To change an actor's image connected to an attribute's number you do this:
    ie. -When touch is pressed-
    -Change Attribute-
    AttributeName to AttributeName+1

    -When AttributeName is 1-
    Change image
    or
    Change self.image attribute to specific picture.

    -When AttributeName is 2-
    Change image
    or
    Change self.image attribute to another specific picture.

    etc.

    Is this what you were looking for?
  • Mr HansonMr Hanson Member Posts: 94
    @carlblanchet

    I think I understand that but what would I do if I have two game attributes l, one that says either blue or red, and the other a number. So when an actor is touch it changes it's image to "game.attributeone game.attributetwo" so it could be blue1 or red9 depending on the variables. Hope that males sense

    All the best
  • carlblanchetcarlblanchet Member Posts: 755
    edited October 2012
    Not so sure I properly understand what you mean. What exactly are you trying to achieve?

    Are you saying that you want this actor to switch back and forth between blue and red when pressed, and also display the number of times it was pressed?
  • Mr HansonMr Hanson Member Posts: 94
    I have a main attribute called game.colour
    When a blue actor is pressed it changes game.colour to blue.

    When the red actor is pressed it changes it to red.

    Once the player has touched either one they then touch another actor. This actor changes another attribute called game.count to plus one.

    Once touched it needs to change it self to game.colour game.count.

    For example if the red actor is touched and then the other actor which sets the count to 2. It needs to change image to red2.png

    Is that easier to understand now @carlblanchet
  • carlblanchetcarlblanchet Member Posts: 755
    edited October 2012
    Ok. To begin, The colour attribute will be an integer where 0 is blue and 1 is red.
    Now for the touch count attribute you should make it a self attribute (except if the count needs to be known by other game mechanics) because this way each actor will have its own count. And also make another colour attribute but this time make it a self attribute.

    Now in the actor:
    -When touch is pressed-
    if game.colour is = 0 and self.colour = 0 (which means if touched with blue colour attribute active and if the actor is already blue)
    -Change Attribute-
    self.count to self.count+1

    -When touch is pressed-
    if game.colour is = 1 and self.colour = 0 (which means if touched with red colour attribute active and if the actor is blue)
    -Change Image- to Red0.png
    -Change Attribute-
    self.count to 0
    -Change Attribute-
    self.color to 1

    -When touch is pressed-
    if game.colour is = 1 and self.colour = 1 (which means if touched with red colour attribute active and if the actor is already red)
    -Change Attribute-
    self.count to self.count+1

    -When touch is pressed-
    if game.colour is = 0 and self.colour = 1 (which means if touched with blue colour attribute active and if the actor is red)
    -Change Image- to Blue0.png
    -Change Attribute-
    self.count to 0
    -Change Attribute-
    self.color to 0

    -If attribute-
    self.colour is 0 and self.count is 1
    -Change Image- to Red1.png
    (do this with all other count numbers)

    -If attribute-
    self.colour is 1 and self.count is 1
    -Change Image- to Blue1.png
    (do this with all other count numbers)

    Does this answer your question?
  • Mr HansonMr Hanson Member Posts: 94
    Right first of thanks for a detailed reply :) @carlblanchet

    I got lost and then I noticed this was what I had done at the start but found i had too many rules because I had five different collies and over 40 other actors. Which comes to a lot of rules.

    So I was hoping I called used change attribute function. And say change self.image to what ever game.colour is and whatever game.count is. This way it will be only a few rules. If you get what I mean. The blue actor is pressed which changes game.colour to blue. Then a non colored actor who has a self.count attribute is touched it will change game.count to self.count. So if the actors count is 6, it will change the game.count to 6.

    The actor will then change self.image to using the equation game.colour,game.count.

    So it will change to the image that has the name blue6.

    This way only one a few rules need to used.

    So I would like to know how I would make the equation work.

    Does that make more sense of what I want. I know how to change an image. I just want to know how to make it into one rule.

    All the best
    JonApp
  • carlblanchetcarlblanchet Member Posts: 755
    edited October 2012
    @JonApp Ohh! Much clearer now haha.
    Take a look at this demo: http://www.2shared.com/file/WTu8pmBd/Demogameproj.html

    I was able to achieve the change of image into 1 rule using table cell values.
  • Mr HansonMr Hanson Member Posts: 94
    @carlblanchet

    Two issues. One is i cant use tables for this and second is I can't open the demo because i haven't updraded to mountain lion. I am getting some error so it's getting fixed soon.

    On one of other templates I had equation on making a custom score:

    Change self.image to "number_"..floor((game.score%self.dev/10))..".png"

    And it works so fine so I thought I could to the same thing. With out using tables.

    Thanks
  • carlblanchetcarlblanchet Member Posts: 755
    edited October 2012
    @JonApp What I had done with the table was I had a text column and an integer column, and I would pull the words from there to get either Red or Blue, then the same with the numbers.

    Therefor all you gotta do is have a text attribute for the colour that is changed between "Red" and "Blue" then have a integer for the count.
    From there you use the change attribute behaviour to say change self.image to self.colour..self.count which will give a result of i.e. Red9, then pulling up the Red9 image.

    You don't really need to have the custom score equation in there, but only the attribute's value. Of course except if you're wanting to display more than 1 number on there.
  • carlblanchetcarlblanchet Member Posts: 755
    Oh and put the change attribute behaviour in a timer-every 0 seconds-run to completion. This might be all that you're missing.
  • Mr HansonMr Hanson Member Posts: 94
    Thanks @carlblanchet

    For the help, I get what you mean using tables, however the equation was just an example to show that there is a way it could be done using change attribute.

    All I really need to know is what equation I would use eg change self.image to "game.colour game.count.png."

    I just don't know how to make the equation work, that's all I pretty need help with. If it's possible.

    I set up the table but I just need this simple equation.

    Thanks
    JonApp
  • carlblanchetcarlblanchet Member Posts: 755
    @JonApp We're making this more complicated than it is aren't we :P haha

    like i said all you need is:

    -Timer-
    Every 0 second - Run to completion
    -Change Attribute-
    self.image to game.colour..game.count
  • Mr HansonMr Hanson Member Posts: 94
    @carlblanchet

    Yes that's exactly what I want but it doesn't work when i put that in an equation. How exactly would I write it.


    Haha I know, but least I learnt some more things.

    All the best
  • carlblanchetcarlblanchet Member Posts: 755
    Damn man, it's so hard for me to tell you specifically how to get this to work in your project because I've told you everything I can say about the subject.

    Try making a display text over that actor with the same code that you're using for the change attribute, and see what this displays. You know your code will be properly done when the text that is displayed is exactly what the images are named.

    I can take a look at your project if you want but I'm afraid that you won't be able to open it after I send it back to you since you weren't able to open the demo I sent.
  • Mr HansonMr Hanson Member Posts: 94
    @carlblanchet

    Thanks keep helping even if it's making frustrated.

    So here is what I have done.

    Open a new project

    Added an image called blue1

    Added an actor called test

    Added two game attributes.

    One is a interger called "count" and is set to 1.

    The other one is a text and is called "colour" and set it to blue.

    On my test actor I have said change self.image to game.colour game.count

    I made another actor that displays the same equation but it says invalid expression .

    This is where I am stuck. So my question is how would I make the expression work??

    Thanks
    JonApp
  • carlblanchetcarlblanchet Member Posts: 755
    @JonApp No worries :)

    add 2 dot (..) in between game.colour and game.count

    it will give you: self.image to game.colour..game.count

    This should do it.
  • Mr HansonMr Hanson Member Posts: 94
    edited October 2012
    It works, thanks so much. It's hard to believe that's all I really needed. Your the best :)

    All the best
    JonApp
  • carlblanchetcarlblanchet Member Posts: 755
    @JonApp Haha xD
    Glad I could help! :)
Sign In or Register to comment.