GetCreeperColors returns all black by default

Started by albrittbrat, October 15, 2013, 04:07:01 PM

Previous topic - Next topic

albrittbrat

So, I was messing around with making my first map, and I wanted to change the color of the creeper on the map based on proximity to a tower. I would like to be able to change it back to default when player units are out of range. In doing so, I realized that running 'GetCreeperColors' at the start of a map, then 'SetCreeperColors' to those default values results in all creeper and anti-creeper being black.

I am not sure if this is a bug or not, but if it is intended, could someone please post what the default color scheme is for Creeper and Anti-Creeper (ie the RGB values for the campaign missions)

I have included a simple example map to show this behavior.


# example.crpl
#-------------
once
#Syntax for these commands is copied directly from syntax on the wiki
GetCreeperColors ->acB ->acG ->acR ->creeperB ->creeperG ->creeperR
SetCreeperColors(<-creeperR <-creeperG <-creeperB <-acR <-acG <-acB)
endonce

Grauniad

The values are GPU floating point values between 0 and 1. You can look in your %appdata%\CreeperWorld3\gameSettings.xml file to find your current values.  Mine are:

  <CreeperRed>0.35</CreeperRed>
  <CreeperGreen>0.3</CreeperGreen>
  <CreeperBlue>0.8</CreeperBlue>
  <ACRed>0</ACRed>
  <ACGreen>0.6</ACGreen>
  <ACBlue>1</ACBlue>

A goodnight to all and to all a good night - Goodnight Moon


knucracker

Don't ask me why, but it looks like GetCreeperColors returns floats (0..1) and SetCreeperColors takes ints (0..255).    They mean the same thing (basically), but are in different ranges.  So you have to multiply the values you get back from GetCreeperColors by 255 when passing them to SetCreeperColors.

It is probably an oversight that they are returned in different ranges, but I'm inclined to leave it at this point since it technically isn't broken but any changes I make would break any maps that rely on the current implementation.

Grauniad

Quote from: virgilw on October 16, 2013, 12:15:09 PM
Don't ask me why, but it looks like GetCreeperColors returns floats (0..1) and SetCreeperColors takes ints (0..255).    They mean the same thing (basically), but are in different ranges.  So you have to multiply the values you get back from GetCreeperColors by 255 when passing them to SetCreeperColors.

It is probably an oversight that they are returned in different ranges, but I'm inclined to leave it at this point since it technically isn't broken but any changes I make would break any maps that rely on the current implementation.

I added this to the relevant wiki pages.
A goodnight to all and to all a good night - Goodnight Moon

Captain Ford

Quote from: virgilw on October 16, 2013, 12:15:09 PM
It is probably an oversight that they are returned in different ranges, but I'm inclined to leave it at this point since it technically isn't broken but any changes I make would break any maps that rely on the current implementation.
I doubt there are very many maps that rely on it right at this moment. But couldn't you just change it to accept either floats or ints?

There would only be an ambiguity problem with values of exactly 1, and that obviously should be treated as floats. Otherwise, if the value if >1, it's an int, and if it's <=1, it's a float.

asmussen

I suppose a secondary function could also be added for each of those, like GetCreeperColorsInt(), and SetCreeperColorsFloat(), so that there would be both an int and a float version of each function available. It'd be a bit of a kludge, but at least would be guaranteed not to mess with any existing maps.
Shawn Asmussen

albrittbrat

Wow, thanks for the info Virgil!
I don't feel like it is a big deal to multiply by 255 now that we all know what is going on. It's just the confusion of not knowing that is annoying. Great game, can't wait to continue scripting!

Grayzzur

Fun with Functions

Unless/until Virgil gives us a GetCreeperColorsInt or its equivalent, there's always user made functions. The downside is having to copy/paste them into every script, as I don't think there's a way to make a utility script and #include it into another.


# Func :GetCreeperColorsInt
# GetCreeperColors that returns values 0-255 instead of 0.0-1.0, to match SetCreeperColors
:GetCreeperColorsInt
GetCreeperColors
CreateList ->gccList
6 0 do
255 mul asint <-gccList swap PrependToList
loop
6 0 do
<-gccList I GetListElement
loop
return
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker