Help trying to recreate Valve's flickering lights in Studio

Hi there,

As the title says, I’m trying to recreate Valve’s flickering light system in Studio as a little challenge to myself. If you want a description of how this system works, pretty much it assigns every letter to a number, with A being off, M being fullbright, and Z being doublebright.

The way I intend to do this is by creating an in pairs loop that will run through each string of numbers and make the light flicker as needed. However, I have no clue what the best way to assign each letter to the respective number is.

I don’t really want to write out every number and make it equal the correct number as that sounds pretty inefficient, but to be honest with you I don’t know any other way to do it. Additionally, if you have any suggestions about alternate methods to the in pairs loop (for making the light actually flicker) then I’d be open to hearing them!

Thanks!

You can take the ASCII number for the letter and normalize it to a number from 0 to 1, then multiply it by the highest brightness value you want

local maxBrightness = 5

Light.Brightness = (string.byte(letter)-97)/25 * maxBrightness

Make sure it’s lowercase, for uppercase you use 65 instead of 97

Edit:
For the opposite you just do the exact opposite of the formula
You lose detail as you convert it to a less specific number system so you have to round out the extra space also

local maxBrightness = 5

letter = string.char(math.floor( (brightness/maxBrightness)*25 + 97 + 0.5))

Played around with this a bit and this does seem to work, however I’ve decided to go the very basic route of just saying that a = 1, b = 2, c = 3 (in a module script). Technically this is a solution to the problem so I will mark your reply as a solution.

Thanks so much for your help though, glad I know how to do this now in case I need to use it in the future!

1 Like