Audiosurf 2 > General Discussions > Topic Details
Random color scheme? (Lua question)
I was wondering if there is any lua code that allows a string of values to be randomly ordered every time you play the game.

For instance, say I wanted to randomize the values that are bracketed by the SetTrackColors.

SetTrackColors{
{r=20, g=0, b=20},
{r=20, g=0, b=80},
{r=51, g=0, b=218},
{r=0, g=0, b=255},
{r=0, g=137, b=255},
{r=0, g=188, b=75},
{r=0, g=255, b=179},
{r=0, g=255, b=137},
{r=0, g=255, b=0},
{r=51, g=255, b=0},
{r=179, g=255, b=0},
{r=255, g=255, b=0},
{r=255, g=119, b=0},
{r=255,g=68,b=0},
{r=255, g=34, b=0},
{r=255,g=0,b=50},
{r=92, g=158, b=255}
}

What would I put in to make the order of the colors random each time I play the game, if its at all possible?
Last edited by Nickalahobiboolan (Hail Deepa); Mar 7 @ 6:32pm
Showing 1-2 of 2 comments
< >
² Mar 7 @ 3:58pm 
I liked this solution: http://forums.wowace.com/showpost.php?p=279715&postcount=3

This is how you make it work in AS: (Remove the \ in [\i], BBCode still works in code tags.)

-- Put your colors here.
TrackColors = {
{r=214, g=0, b=254},
{r=0, g=176, b=255},
{r=0, g=184, b=0},
{r=255, g=255, b=0},
{r=255, g=0, b=0}
}

-- Replace 5 with the amount of colors you have.
-- Lua can't count table entries by itself for some reason.
for i = 5, 2, -1 do
local r = math.random(i)
TrackColors[\i], TrackColors[r] = TrackColors[r], TrackColors[\i]
end

-- Same here.
SetTrackColors{
TrackColors[1],
TrackColors[2],
TrackColors[3],
TrackColors[4],
TrackColors[5]
}
Last edited by ²; Mar 7 @ 4:00pm
Thank you, it works perfectly. My only question, if you know, does it choose each color only once or can it select the same color in 2 different positions of the order? Also, does it randomly choose the order on each bootup of the game, or each song bootup?

EDIT: I see that this method works for creating each song with a unique color scheme that doesnt change, but each song has a different order. Very cool.
Last edited by Nickalahobiboolan (Hail Deepa); Mar 7 @ 6:36pm
Showing 1-2 of 2 comments
< >
Per page: 15 30 50
Date Posted: Mar 7 @ 3:22pm
Posts: 2