Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: CaptainD on Fri 27/07/2018 23:16:16

Title: Can you use variables with Game.GetColorFromRGB?
Post by: CaptainD on Fri 27/07/2018 23:16:16
I've been trying to use variables with this command but the results appear to bear no resemblance to what they should.  Basically I have:

Code (ags) Select
c=Game.GetColorFromRGB(r, g, b);

r, g and b are integers ranging from 0-255, and I then set the surface drawing colour to c.  Obviously I'm doing something wrong, or I'm simply trying to do something that can't be done with this command.  Any ideas?
Title: Re: Can you use variables with Game.GetColorFromRGB?
Post by: Crimson Wizard on Fri 27/07/2018 23:25:17
This is the correct way of using this commmand, and there is absolutely no difference whether you use literal numbers or variables there. But I could not understand what the problem exactly is from your explanation. Can you give more details - what do you expect, and what do you get?
Title: Re: Can you use variables with Game.GetColorFromRGB?
Post by: morganw on Sat 28/07/2018 02:07:33
The colour is an integer, so unless you've already declared it:
Code (ags) Select
int c = Game.GetColorFromRGB(r, g, b);
Title: Re: Can you use variables with Game.GetColorFromRGB?
Post by: CaptainD on Sat 28/07/2018 10:35:31
morganw - yes I've set C as a variable.

CW - the problem is that the colours are nothing like what I'd expect.  So for instance R=0 G=0 B=0; each game cycle draws a circle and increments b by 1; I'd expect to see a gradually brightening blue colour.  However the colours are all over the place, they don't even have a predominance of blue to them.  Also it appears to be using a very limited colour palette no matter what colour depth I set the game to.

(https://4.bp.blogspot.com/-ZDrp9GUiXEE/W1w3UlAx3pI/AAAAAAAAtdo/2VPclatJ8KM7jqlwo1qqGY8ixQFMZpUHQCLcBGAs/s320/circles.png)


Essentially this is the code that's doing this part every loop.  Nothing fancy at all.

Code (ags) Select
c=Game.GetColorFromRGB(r, g, b);
   
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = c;
surface.DrawCircle(x,y, size);
surface.Release();

b++;

if (b>255) b=0;


I just don't get what I'm doing wrong, but clearly I'm doing something wrong!
Title: Re: Can you use variables with Game.GetColorFromRGB?
Post by: Crimson Wizard on Sat 28/07/2018 13:01:53
I do not remember if this was documented, but certainly mentioned on forums few times before.

The first several (16 or 32) color indexes in AGS are special system colors, and I think you need to start Red and Green with 4 to avoid using them.
In other words, iterate Red and Green from 4 to 255, and blue from 0 to 255.

EDIT: This is mentioned on the Color Picker pane in AGS. The only color that needs to be restricted to 4+ is Green.

So, Green must go from 4 to 255, other components may be from 0 to 255.
Title: Re: Can you use variables with Game.GetColorFromRGB?
Post by: CaptainD on Sat 28/07/2018 13:42:30
Thanks CW!