storing color as a single object

Monkey Forums/Monkey Programming/storing color as a single object

C10B(Posted 2013) [#1]
Hi,
Is this possible? (this is my sudo code that I would like to be able to do)...


Global LovelyColor=[215,35,222]

SetColor LovelyColor

It would make is really easy for reusing colors in my app.

Thank you


Jesse(Posted 2013) [#2]
no but you can roll your own function:
Global LovelyColor:int[] = [215,35,222]

SetColor(LovelyColor)

Function SetColor:Void(c:int[])
	mojo.SetColor c[0],c[1],c[2]
End Function



Belimoth(Posted 2013) [#3]
I have something similar that I use a lot. I have it as a submodule in my Abu framework but here it is seperately:



You can put it either in your project folder or the modules folder, and then add this to the top of any file that uses it:
Import mojomodifications
Alias SetColor = mojomodifications.SetColor
Alias Cls = mojomodifications.Cls

Then I make color constants like this:
Const COLOR_WHITE:Int = $FFFFFF
Const COLOR_GREEN:Int = $00FF00
...
Cls(COLOR_WHITE)
SetColor(COLOR_GREEN)

Maybe hex codes aren't your thing but I find them useful :)

EDIT: I've added the array strategy. Be careful Jesse, mojo SetColor's return type is Int.


Jesse(Posted 2013) [#4]
I don't know what you you mean.

my example works fine here v67b.


Belimoth(Posted 2013) [#5]
Hmm, I thought I remembered having a problem overloading functions like that before but I was mistaken. Sorry.


Gerry Quinn(Posted 2013) [#6]
I had overloading issues too, though I imagine they could be overcome using Alias.

As a RightPondian, my solution was to make a SetColour() function.