I want to leave custom space between two lines of text.
I wanted to do something similar to
cursor(x,y) print("first line") cursor(current_x(), current_y()+2) print("second line") |
for this, I tried reading the cursor position with peak
function get_cursor() local x = peek(0x5f26) local y = peek(0x5f27) return x,y end |
But with this, you only get the least significant byte of each coordinate, and when the x is negative or > 255, I get problems.
Is there an easy way to solve this?
Thanks!
The text appears in a fixed point of a map. Since I use camera() to move stuff around, I can have text in negative X or in X > 256, which is then translated automatically.
What I want to do:
I have a multiline text, and I want to print an extra line after that text, separated by a custom number of pixels (instead of 8).
I initially wanted to do:
cursor(startx, starty) print(multiline_text) -- cursor has a new position. I want a bit more spacing cursor(newx, newy+3) print(last_line) |
I guess I could do something like
cursor(startx, starty) print(multiline_text) cursor(startx, starty + lines*8 + 3) |
Doesn't seem too hard, but I was wondering if there was an easy way to do what I initially wanted to do.
This is one reason why I wish @zep would change it so cursor() would return a tuple with the existing coords.
It'd be useful for a lot of stuff, including yours, but it'd mainly be useful for things like this:
function alert() -- remember current cursor position and move to center local savex,savey=cursor(52,61) -- print message print("alert!") -- restore cursor position cursor(savex,savey) end |
Or, could also be written...
function alert() -- remember current cursor position local savex,savey=cursor() -- print message at center print("alert!",52,61) -- restore cursor position cursor(savex,savey) end |
Tiny API changes like this can go a long way towards making app code simpler and more elegant.
[Please log in to post a comment]