Legacy GM random background color[SOLVED]

L

Lgmsfan

Guest
hi all just wanting some help with random background color at start of a room heres what i was trying with little luck

//in create event of object in room
global.cola=make_colour_rgb(100,145,125);
global.colb=make_colour_rgb(100,125,225);
global.colc=make_colour_rgb(200,115,115);
global.cold=make_colour_rgb(150,105,105);
//
randomize();
choose(scr_bgc3(),scr_bgc1(),scr_bgc2());//choose a background color from scripts

//in external scripts
//in scr_bgc1//
background_colour=global.cola;
background_showcolour=true;

//in scr_bgc2//
background_colour=global.colb;
background_showcolour=true;

and in scr_bgc3//
background_colour=global.colc;
background_showcolour=true;

//the problem im having is that it always only calls the first scripts color and never any other any help would be great Thanks GMC.
 

TsukaYuriko

☄️
Forum Staff
Moderator
You're treating script execution calls like values. They are not values. choose can not be used to call a random script the way you are trying to do it.

Why you're even using scripts when you could simply set the background color to a choosen value and therefore shrinking your code down to one line (or five if you want to keep the color variables) is beyond me. ;)
 
D

DarthTenebris

Guest
An easy way to create a random color is:
Code:
randomize();
global.col = make_color_rgb(random(255), random(255), random(255));
background_color = global.col;
background_showcolor = true;
It's that simple :)
Hope I helped :)
 
L

Lgmsfan

Guest
You're treating script execution calls like values. They are not values. choose can not be used to call a random script the way you are trying to do it.

Why you're even using scripts when you could simply set the background color to a choosen value and therefore shrinking your code down to one line (or five if you want to keep the color variables) is beyond me. ;)
hi thanks for your wisdom could you please show me a example of what you mean if its not too much of your time

An easy way to create a random color is:
Code:
randomize();
global.col = make_color_rgb(random(255), random(255), random(255));
background_color = global.col;
background_showcolor = true;
It's that simple :)
Hope I helped :)
Thanks ill give it a go : )

An easy way to create a random color is:
Code:
randomize();
global.col = make_color_rgb(random(255), random(255), random(255));
background_color = global.col;
background_showcolor = true;
It's that simple :)
Hope I helped :)
nice but how would i make it choose from a set of colors i have only

An easy way to create a random color is:
Code:
randomize();
global.col = make_color_rgb(random(255), random(255), random(255));
background_color = global.col;
background_showcolor = true;
It's that simple :)
Hope I helped :)
you see my player would change color to the random selected color chosen at start of room
a selection of 3 colors to choose from
 
Last edited by a moderator:
D

DarthTenebris

Guest
Woah triple post :eek:

How it works: Look up the function make_color_rgb(red, green, blue);
RGB color format consists of red value, green value and blue value. And they all range from 0-255 (all 0 for pure black and all 255 for pure white). Look it up on google for more info.

But yeah, if you want to select from some colors only you could use:
Code:
global.col = choose(color_1, color_2, color_3); //or more - up to 16 arguments can a function receive
A list of pre defined colors: A list of pre defined colors
 
L

Lgmsfan

Guest
Woah triple post :eek:

How it works: Look up the function make_color_rgb(red, green, blue);
RGB color format consists of red value, green value and blue value. And they all range from 0-255 (all 0 for pure black and all 255 for pure white). Look it up on google for more info.

But yeah, if you want to select from some colors only you could use:
Code:
global.col = choose(color_1, color_2, color_3); //or more - up to 16 arguments can a function receive
A list of pre defined colors: A list of pre defined colors
NICE THANKS HEAPS FOR YOUR HELP THIS IS HOW I DID IT AND IT WORKS GREAT THANKS AGAIN


global.cola=make_colour_rgb(100,145,125);
global.colb=make_colour_rgb(100,125,225);
global.colc=make_colour_rgb(200,115,115);


randomize();
global.col=choose(global.cola, global.colb, global.colc); //
background_color = global.col ;
background_showcolor = true;
 

NightFrost

Member
Also, if you need to choose from more colors than choose() can handle, you can use an array.
Code:
global.Palette[0] = make_color_rgb(100, 100, 100);
global.Palette[1] = make_color_rgb(200, 100, 100);
...
global.Palette[500] = make_color_rgb(255, 255, 255);
...
SelectedColor = global.Palette[irandom(array_length_1d(global.Palette) - 1)];
 
L

Lgmsfan

Guest
Also, if you need to choose from more colors than choose() can handle, you can use an array.
Code:
global.Palette[0] = make_color_rgb(100, 100, 100);
global.Palette[1] = make_color_rgb(200, 100, 100);
...
global.Palette[500] = make_color_rgb(255, 255, 255);
...
SelectedColor = global.Palette[irandom(array_length_1d(global.Palette) - 1)];
Thanks ill have to look into that as well Thanks

Also, if you need to choose from more colors than choose() can handle, you can use an array.
Code:
global.Palette[0] = make_color_rgb(100, 100, 100);
global.Palette[1] = make_color_rgb(200, 100, 100);
...
global.Palette[500] = make_color_rgb(255, 255, 255);
...
SelectedColor = global.Palette[irandom(array_length_1d(global.Palette) - 1)];
Just curious do you know how many colors choose can handle?
 
Last edited by a moderator:
D

DarthTenebris

Guest
choose() is a function - all functions (and scripts) - can handle up to 16 arguments each (argument0 - argument15) and therefore, in this case, can choose up to 16 different colors. If you want to bypass that, you can try to use irandom(x) and a switch() statement.
 
L

Lgmsfan

Guest
choose() is a function - all functions (and scripts) - can handle up to 16 arguments each (argument0 - argument15) and therefore, in this case, can choose up to 16 different colors. If you want to bypass that, you can try to use irandom(x) and a switch() statement.
THANKS GOOD TO KNOW 16 IS PLENTY AT THIS STAGE BUT GOOD TO KNOW I HAVE A OPTION TO DO MORE IF I NEEDED TO
 
D

DarthTenebris

Guest
I simply have to tell you - you've broken at least 3 forum rules :rolleyes:
Not trying to judge you though - glad you solved your problem.
 
L

Lgmsfan

Guest
I simply have to tell you - you've broken at least 3 forum rules :rolleyes:
Not trying to judge you though - glad you solved your problem.
sorry i didnt know i broke any rules glad for all the help though the GMC is great for people
 

TsukaYuriko

☄️
Forum Staff
Moderator
THANKS GOOD TO KNOW 16 IS PLENTY AT THIS STAGE BUT GOOD TO KNOW I HAVE A OPTION TO DO MORE IF I NEEDED TO
The shift or caps lock keys are to be used in moderation, not in masses. The same goes for the Post Reply button. :p

That aside, the 16 argument limit no longer exists in recent versions of GM:S. You can use as many as your hardware can handle.
 
Top