Random scene selection except for the one you're currently on

msx88msx88 Member, PRO Posts: 27

I’ve got a random scene selection between 3 and 21 but I was wondering how I could tell it to not select the one that you’re currently on.

Is there a way to say “randomly select between scenes 3 and 21 except for scene __” ?

I’ve found a couple of similar threads from the past on this subject but they didn’t work for me.

Thanks in advance.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited July 2016

    Thanks to @Socks for this...

    If you wanted a number between 3 and 21 except 17 (for example), you would use this expression:

    (17+random(0,19))%21+1

    Which results in these possible values:

    (17+0)%21+1=18
    (17+1)%21+1=19
    (17+2)%21+1=20
    (17+3)%21+1=21
    (17+4)%21+1=1
    (17+5)%21+1=2
    (17+6)%21+1=3
    (17+7)%21+1=4
    (17+8)%21+1=5
    (17+9)%21+1=6
    (17+10)%21+1=7
    (17+11)%21+1=8
    (17+12)%21+1=9
    (17+13)%21+1=10
    (17+14)%21+1=11
    (17+15)%21+1=12
    (17+16)%21+1=13
    (17+17)%21+1=14
    (17+18)%21+1=15
    (17+19)%21+1=16

    For a different exception value, just change the 17 in that expression to something else. So for example, to exclude 6, the expression would be:

    (6+random(0,19))%21+1

    Source: http://forums.gamesalad.com/discussion/comment/577360/page1

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

  • msx88msx88 Member, PRO Posts: 27

    Thank you so much for your help @tatiang and @Socks, you guys rock.

    I've tried the (17+random(0,19))%21+1 expression and yes, it never picked Scene 17 but it did pick up Scenes 1 and 2 which I'm trying to avoid. I was wondering how I can exclude those as well.

    So I played around with it a little bit and tried something like (17+random(3,19))%21+1 but it still ended up picking 1 and 2. What kind of modification to the code would work?

    In essence, I would like to have random scenes between 3 and 21 picked, but exclude scenes 1, 2 and the current scene I'm on (for ex. 6). I've attached a sample screen shot.

    Thanks in advance.

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

    @jimmyxpark said:
    In essence, I would like to have random scenes between 3 and 21 picked, but exclude scenes 1, 2 and the current scene I'm on (for ex. 6)

    ((6-3)+random(1,18))%19+3

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Sorry, I forgot your initial requirement for 3 as the minimum.

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

Sign In or Register to comment.