GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Randomly Change Image

Dizzy PugDizzy Pug Posts: 41Member
edited March 2012 in Working with GS (Mac)
Hello again GS forum!

I'm back with another query that I thought you could help me with.

How can I have an actor change an image, at random, between a given 5 to 15 seconds?

For example: A white block, at some time between 5 and 15 seconds, changes colour to either a red or blue block (Randomly chosen). The new colour is displayed and will also change to either white or blue after 5 to 15 seconds.

Thanks in advance

-Blackmill

Best Answers

  • JohnPapiomitisJohnPapiomitis Posts: 6,256Member
    Accepted Answer
    Yeah, and its easier changing to a image cause you dont need all the behaviors.

    Do the same as above except for the rules have them like this

    when randomColor=1
    -change image behavior to image 1

    when randomColor=2
    -change image behavior to image 2

    when randomColor=3
    -change image behavior to image 3


    Then you would just keep going like that if you want more. Just if you do, change the random in the change attribute to the amount of images you want. For example if you want 10, you would change randomColor to random(1,10)

    and then have the rules for the rest of the images like above

    cheers
  • CodeMonkeyCodeMonkey Posts: 1,803Head Chef, Member, PRO
    Accepted Answer
    Here is an even easier way. Create a table with a text type column. That column will contain names of images(one per row). When you do a randomize, just use a Change Attribute on the self.Image attribute and change it to the cell value.

    e.g. tableCellValue(Images,random(1,tableRowCount(Images)),1)

Answers

  • JohnPapiomitisJohnPapiomitis Posts: 6,256Member
    Make an attribute called randomColor

    Have a timer every 15 seconds (or however many seconds you want)
    -change attribute randomColor to random(1,3)

    Make a rule when attribute randomColor=1
    -change attribute self color red to 1
    -change attribute self color blue to 0
    -change attribute self color green to 0

    that will change it to red

    Make a rule when attribute randomColor=2
    -change attribute self color red to 0
    -change attribute self color blue to 1
    -change attribute self color green to 0

    that will change it to blue

    Make a rule when attribute randomColor=3
    -change attribute self color red to 1
    -change attribute self color blue to 1
    -change attribute self color green to 1

    that will change it to white

    cheers
  • Dizzy PugDizzy Pug Posts: 41Member
    Instead of colour, could it possibly be an image?
  • Dizzy PugDizzy Pug Posts: 41Member
    Brilliant! You sir are my saviour.

    Just a quick addition:

    Is it possible to say:

    -image behaviour to image 1
    -Actor 1, on touch, adds +1 to the total score
    -Actor 2,3 and 4, minus 1 life
    -image behaviour to image 2
    -Actor 2, on touch, adds +1 to the total score
    etc.

    -Thanks again

    Blackmill
  • Dizzy PugDizzy Pug Posts: 41Member
    Tables hmm... I'll give it a shot.

    Thanks

    -Blackmill
  • Dizzy PugDizzy Pug Posts: 41Member
    Query:

    It starts off displaying itself as a 'blank' actor and after 15 seconds it changes. How do I make it so that it is displaying a random colour at the beginning of the game?

    -Blackmill
This discussion has been closed.