Copies of one actor on scene behave differently.

saad1993saad1993 Member, BASIC Posts: 47

I have an actor on scene and what it does is, it changes color every 5.5 seconds after randomly choosing colors from a table. When I add copies of that actor by using Alt and drag, I assumed that these copies will follow the same color that the original does. However, That is not the case.

I want to be able to make 3 extra copies of the original actor and have them change to the same RANDOM color after 5.5 seconds (Which is the duration I am using on the timer).

Comments

  • IceboxIcebox Member Posts: 1,485

    Create 3 integer game attributes Red, Green, Blue

    change attribute game.Red to random(0,1)
    change attribute game.Blue to random(0,1)
    change attribute game.Green to random(0,1)

    After 5.5 seconds
    change attribute self.blue to Game.Blue
    change attribute self.green to Game.Green
    change attribute self.Red to Game.Red

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @Icebox said:
    Create 3 integer game attributes Red, Green, Blue

    change attribute game.Red to random(0,1)
    change attribute game.Blue to random(0,1)
    change attribute game.Green to random(0,1)

    The random function produces only whole number values, so will only be changing each colour channel between two values (0 and 1, or 'on' and 'off'), which will mean a random selection from just 6 'colours', which are the 3 primaries (red, green and blue) and the 3 secondaries (yellow, cyan and magenta) . . as well as black and white, but for random colour generation, generally speaking, we often want to avoid black and/or white, as black and/or white are common background colours.

    24bit colour actually contains 16,777,216 colours, so using random(0,1) discards 16,777,210 of those colours (99.999964% of the available colours) !

    You can access the full 16,777,216 colours (including black and white) with:

    change R to random(0,255)/255
    change G to random(0,255)/255
    change B to random(0,255)/255

    If you want to avoid black, you can limit the lower range of the random function like this:

    change R to random(50,255)/255
    change G to random(50,255)/255
    change B to random(50,255)/255

    If you want to avoid white, you'd limit the upper range, like this:

    change R to random(0,200)/255
    change G to random(0,200)/255
    change B to random(0,200)/255

    If you wanted light/pastely (is that even a word ?) colours, you'd just use the top of the range, like this:

    change R to random(200,255)/255
    change G to random(200,255)/255
    change B to random(200,255)/255

    Random greens:

    change R to random(0,128)/255
    change G to random(128,255)/255
    change B to random(0,128)/255

    Random blues:

    change R to random(0,128)/255
    change G to random(0,128)/255
    change B to random(128,255)/255

    . . . etc etc

  • IceboxIcebox Member Posts: 1,485

    I was wondering why the colors were limited ! thanks for the info :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @Icebox said:
    I was wondering why the colors were limited ! thanks for the info :)

    Yeah, the random function catches people out all the time, a 'real' random function would be good, something like . .

    randomReal(0,1)

    . . . that generates 'real' values like 0.45311 or whatever, having two randoms in the pull down function menu would make people aware of the difference, but at the end of the day once you are aware of how it works the maths to generate real values from integers is very straightforward.

    Here's one more random random colour method !!

    change R to (sin( game.Time *1234.567)/2)+0.5
    change G to (sin( game.Time *58008)/2)+0.5
    change B to (sin( game.Time *3.14)/2)+0.5

    Using this method, you can duplicate multiple copies of the actor and their random colour will stay in sync without the need for 3 game attributes.

  • IceboxIcebox Member Posts: 1,485

    This is a method only you can come up with :) a bit complicated , i dont know how you came up with the numbers ill test it when i go back home

  • SocksSocks London, UK.Member Posts: 12,822

    @Icebox said:
    i dont know how you came up with the numbers . .

    The first number is simply 1234567
    The second number spells 'boobs' when typed on a calculator and turned upside down*.
    The thirst number is Pi.

    *very important :)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Socks said:

    @Icebox said:
    i dont know how you came up with the numbers . .

    The first number is simply 1234567
    The second number spells 'boobs' when typed on a calculator and turned upside down*.
    The thirst number is Pi.

    *very important :)

    @Socks wins the internets!

  • SocksSocks London, UK.Member Posts: 12,822

    @RThurman said:
    @Socks wins the internets!

    Lol, I'm glad you recognise the hard work and thought I put into those numbers :) ;)

Sign In or Register to comment.