Skip to content

Instantly share code, notes, and snippets.

@realStandal
Created June 15, 2019 15:27
Show Gist options
  • Save realStandal/bc25de46252e0f4817a6ce7e8cf0f2a2 to your computer and use it in GitHub Desktop.
Save realStandal/bc25de46252e0f4817a6ce7e8cf0f2a2 to your computer and use it in GitHub Desktop.
Stormworks Rows
-- Constant values
local CONST_CHAR_HEIGHT = 5
local CONST_CHAR_WIDTH = 4
local CONST_LINE_SPACING = 1
function onTick()
-- Example that adds two composite channels together and outputs the result
in1 = input.getNumber(1)
in2 = input.getNumber(2)
output.setNumber(1, in1 + in2)
end
function onDraw()
-- Example that draws a red circle in the center of the screen with a radius of 20 pixels
width = screen.getWidth()
height = screen.getHeight()
screen.setColor(255, 255, 255)
-- Our list of strings to display vertically.
local strings_to_display = {
"One line",
"ah!! two lines!",
"AHHH!!!! THREE!!!! LINEEESSS!!"
}
-- Extended drawTextBox:
-- Automatically configures height based off intended width of box.
-- Expects a table of strings to display.
function drawTextBoxEx(origin_x, origin_y, width, text_list)
local y_val = origin_y
for index in ipairs(text_list) do
screen.drawTextBox(origin_x, y_val, width, 6, text_list[index])
local text_string = text_list[index]
local string_length = string.len(text_string) -- Retrieve the length of our string.
local char_predic = string_length * CONST_CHAR_WIDTH -- Compute the width our text would take up on a single line.
local line_count = math.ceil(char_predic / width) -- Compute the number of lines required to fit this line of text in a container of the specified width.
y_val = y_val + line_count * (CONST_CHAR_HEIGHT + CONST_LINE_SPACING)
end
end
drawTextBoxEx(0, 0, 150, strings_to_display)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment