Stormworks: Build and Rescue

Stormworks: Build and Rescue

Selva [Hk] Jul 23, 2020 @ 1:12pm
LUA - Change Text Colors According to Values
Hello folks, im very deep into advanced vehicle building and i'm starting to do some basic LUA stuff to use monitors. However, i can't figure out how to, properly, change the text colors base on the values of X or Y, for example.

I want different colors according to values. I've tried using the IF and ELSE statements, but the synthaxes never worked.

Also, i never had experience with LUA or programming.
< >
Showing 1-4 of 4 comments
ElfBossHogg Jul 23, 2020 @ 1:36pm 
The screen.setColor(r,g,b,t) is actually quite easy to use. When you issue the command every subsequent draw will be done in that color until you issue it again to change the value. The values of r(ed), g(reen) and b(lue) range from 0-255 and correspond to a standard RGB colour chart. Just do a search for "RGB color picker" and Google has its own tool. The value of t corresponds to transparency. It's basically the opaquness of that colour.
Last edited by ElfBossHogg; Jul 23, 2020 @ 1:38pm
Unit 744 Jul 23, 2020 @ 4:35pm 
ElfBossHogg gave a great answer. Since you said you were newer to LUA, here is a simple example to give you some ideas how to use this:


if x>10 and y<5 then

screen.setColor(255,0,0) --Sets color to red if x>10 and y<5. Omitting the last t value defaults it to 255, full opaque.

elseif x<10 then

screen.setColor(0,255,0) --Sets to green if x<10 and the above 'if' statement was false.

else

screen.setColor(255,255,255) --Sets to white if none of the above 'if' statements were true.

end

screen.drawCircle(x,y,3) --draws a circle centered at x,y of radius 3. The color will depend on the values of x and y, as dictated in the above 'if' statements.


You can also do interesting things like:

screen.setColor(x*10, y-20, x), where the r,g,b values use x and y as variables.


Try this fun example. Set up a throttle lever and a monitor in your cockpit. Input the throttle lever value into LUA.

screen.setColor(255*(1-throttle),255*throttle,0)
screen.drawRectF(1,1,10,10)

This will draw a square that changes color based on the throttle value. At zero throttle, the square is red; at 0.5, it is yellow (actually it is more brown - you can fix this, but that is not the point of the example); at 1, it is green. This clever use of variables can allow you to do really cool visual representations of the status of your creation and make your cockpit really shine.


Hope this helps!
Last edited by Unit 744; Jul 23, 2020 @ 8:13pm
izmebee Jul 23, 2020 @ 5:29pm 
I really appreciate this, now I realize why my attempts were failures.

I wasnt throwing errors but I wasnt getting results either.
Selva [Hk] Jul 24, 2020 @ 10:59am 
Thank you fellas, i'm gonna try. I knew how to change colors using the RGB codes, but i was not finding the IF correct synthax to them change according the imput values.
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Jul 23, 2020 @ 1:12pm
Posts: 4