Changing image in the prefered order? A challenge.

nypraisenypraise Member, PRO Posts: 96
edited August 2012 in Working with GS (Mac)
I have a mini game for my game where I was thinking of having objects bounce around on the screen and the user will have to press the objects, the objects then change image to a number. Starting from 1 to 5. It´s easy to set up a rule to change image, but I need to have it this way : The first object that is pressed will have to show the image of the number 1, then the number 2, then the number 3 etc. Does this make any sense? :P

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    edited August 2012
    **one way**
    …use tables
    in actorPrototype add attribute … index type … named myRow
    set it to numbers 1 thru 5 on each actor instance in scene

    create table TB-images … 5 rows : 1 column
    in the column … text type … type in names of the number images (exactly as they are in your import … but you do not need to add the .png)

    on actorPrototype:
    -changeAttribute: self.Image To: tableCellValue(select TB-images,select myRow, 1)
    (this sets the first image to display)

    Rule: when
    Attribute: self.myRow > 5
    -changeAttribute: self.myRow To: 0

    Rule: when
    Event: touch is pressed
    -changeAttribute: self.myRow To: self.myRow+1
    -changeAttribute: self.Image To: tableCellValue(select TB-images,select myRow, 1)
    (when you want them to continue after one touch … use a Timer with Run to completion)

    **another way**
    name your instances of onePrototype: 1 thru 5
    -changeAttribute: self.Image To: self.Name

    Rule: when
    Event: touch is pressed
    -changeAttribute: self.Tags To: do

    Rule: when
    Attribute: self.Tags is do
    -Rule: when
    -Attribute: self.Name is 1
    -Animate (drag in image 2; 3; 4; 5; 1) : √ Loop
    -Otherwise:
    --Rule: when
    --Attribute: self.Name is 2
    --Animate (drag in image 3; 4; 5; 1 ;2) : √ Loop
    --Otherwise: for 3, and 4; and 5

    **and of course you could use Timers**
    Every: 1 second
    -changeAttribute: self.Image To self.Image+1

    Rule: when
    Attribute: self.Image = 5
    Timer: After: 1 second
    -changeAttribute: self.image To: 1


    @};- MH
  • nypraisenypraise Member, PRO Posts: 96
    Thanks for your time, MotherHoose. I tried your table version but I can´t seem to get it right. When you said "set it to numbers 1 thru 5 on each actor instance in scene" did you mean like I did on the picture below or did you mean myRow=1 on the first ball(actor), myRow=2 on the secound ball(actor) etc.? I tried both but neither seem to work. Take a look at the pictures and tell me what I am doing wrong? As you can see them numbers is name 1.png, 2.png etc. so just 1,2,3 should be right in the table, correct?

    http://img4.imageshack.us/img4/1795/20120809101409pm.png

    http://img19.imageshack.us/img19/6732/20120809101334pm.png

    http://img256.imageshack.us/img256/2376/20120809101316pm.png

    http://img442.imageshack.us/img442/7713/20120809101240pm.png

    Thanks for your help. :)
  • MotherHooseMotherHoose Member Posts: 2,456
    I am sorry … not so clear …

    one 'myRow' attribute on the Prototype (not 5)
    on the 5 actorInstances change that attribute from 0 to a number: 1 or 2 or 3 or 4 or 5

    table looks great … (didn't actually need but always good to know how to do!)

    rules/behaviors look good

    but please title/name/comment them in their titleBar:

    Rule: touchPressed > myRowChange; imageChange
    Rule: myRow = 5 > reset to 1

    that will remind you what you want to do and make problem finding easier

    think if you delete the extra 'myRow' … things should work super!

    image MH
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Do you want each actor to cycle through images 1 to 5? So if you click on actor A once, it then shows as image 2? Or do you want all of the actors on the screen to cycle so that if you click on any actor, all of the actors show as image 2?

    Either way, wouldn't it be easiest to have an attribute self.clickCount (index) and increase it with each Touch is Pressed? And then have a few rules that say When self.clickCount = 1 --> Change Image [image #1]; When self.clickCount = 2 --> Change Image [image #2], etc.? And then if you want all actors to work that way, use a game-level attribute instead of an actor-level attribute.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • nypraisenypraise Member, PRO Posts: 96
    MH : I delete the extra myRow, but still won´t work. :/

    @tatiang : I have 5 footballs on the screen. When the player press any one of the balls I want it to change image of the number 1, when the secound ball is pressed I want it to change to a image of the number 2 etc. It is important that an image of the number 2 don´t show the first time a ball is pressed or the number 1 the last time. It has to be in the order of 1 to 5. A tool to help children to count. Make any sense? :P
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012

    Hi @nypraise The method @tatiang suggested will work fine for you then, except make the ClickCount attribute a game integer attribute. To add more detail:

    In your football 1 actor: When touch is pressed and game.ClickCount = 0
    Change Image
    Change Attribute game.ClickCount to 1

    In your football 2 actor: When touch is pressed and game.ClickCount = 1
    Change Image
    Change Attribute game.ClickCount to 2

    etc.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • nypraisenypraise Member, PRO Posts: 96
    But won´t the player have to press the correct ball to get the correct result? Can the player press any ball and get the image of number 1 first? And any ball second to get the image of number 2?
  • nypraisenypraise Member, PRO Posts: 96
    This is how I put it now.

    If the image is pressed and the countClick is 0 it shows the image 1 and change the attribute to of countClick to 1.

    Otherwise is the image is pressed and the countClick is 1, it will show the image of number 2 and change the attribute to 2 etc.

    And just have 5 balls with the same rules.
    I would think this would solve the problem, but what happens is when I press the actor/ball in the preview is that it shows image 1 for 0.001 sec and jumps right to image 2. For me it seems like it don´t understand the "otherwise" command. Couse it should not change to the image of 2 unless the countClick is 1.

    Any thoughts?


    image
  • MotherHooseMotherHoose Member Posts: 2,456
    oh that is much easier … @nypraise

    on numberActor:
    add attribute … boolean … named done
    Rule: when
    Event: touch is pressed
    Attribute: self.done is false
    -changeAttribute: clickCount To: clickCount+1 (before image changes)
    -changeAttribute: self.Image To: clickCount
    -changeAttribute: self.done To: true

    clickCount default is 0
    then changes to 1 … which is the name of the image you want
    then changes self.Image To: the # in clickCount … which is 1

    the next numberActor touched will first change the clickCount To: 2
    then changes self.Image To: 2

    image MH
  • nypraisenypraise Member, PRO Posts: 96
    That did not work. :/ First ball changed to image of 1, but so did also the second ball etc.

    I did it right?

    What is the purpose of this Done attribute? I don´t get it.

    image
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012
    But won´t the player have to press the correct ball to get the correct result?
    I misunderstood what you're after then; you weren't clear enough; I thought that was what you wanted to happen.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited August 2012
    This is what I tried to determine earlier. Can you answer A or B below?

    (a) When the player clicks on a ball, only that ball changes its number. So if all of the balls have a 1 on them and the player clicks a ball, that ball changes to 2 and every other ball is still 1.

    (b) When the player clicks on a ball, every ball changes its number. So if all of the balls have a 1 on them and the player clicks a ball, all of the balls are now 2.

    edit: (c) Wait, I think I'm understanding better now. You want it so that when a player clicks the first ball, it changes to 1, and when a player clicks the second ball, that ball changes to 2. Aha!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited August 2012
    Better yet, here's a demo that applies both possibilities. Scene 1 is choice A above and Scene 2 is choice B above.

    [Attachment removed; see below]

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited August 2012
    Okay, I think this might be closer to what you want (see Scene 3). The way I have it setup, it only works once, but the rules should give you an idea of how to get this working.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • nypraisenypraise Member, PRO Posts: 96
    Awesome, Tatiang. That did the trick. Maybe I did a bad job explaining myself. :P But what is the difference between game.clickCount and self.clickCount? Do you have Skype so you can tell me/teach me and not just show me what I just did. :P
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @nypraise, I'm glad it helped! I don't have time to Skype at the moment, but feel free to post on the forums or send me a message here. I check it very frequently.

    The difference between a game attribute and an actor attribute is that a game attribute is a single attribute that any actor can reference, while an actor's attribute is only visible (normally) to that instance of the actor. So in this case, if game.clickCount increases (from 1 to 2), then all of the actors see game.clickCount as a higher number (2). But if you have different actors or multiple instances of an actor and self.clickCount increases (from 1 to 2) on an actor, the other actors don't have access to that attribute. Their own self.clickCount would remain at 1 (or whatever it was before).

    When you want to make a new attribute, ask yourself if other actors need to know the value of that attribute. If so, make it a game-level attribute. If not, make it an actor-level (self.) attribute. Examples of these would be game.currentLevel, game.allEnemiesSpeed, self.position.X, etc.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • nypraisenypraise Member, PRO Posts: 96
    Ahh, good explaination. :) Thanks again for your help. :)
Sign In or Register to comment.