Log In  

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!

P#51174 2018-04-02 09:47 ( Edited 2018-04-02 21:06)

1- how come do you get negative coordinates?
2- tracking y is easy, text has variable width but fixed height (6 I guess). Each time you print something, increment y.
3- would be clearer if you tell us what you are trying to achieve ;)

P#51179 2018-04-02 10:09 ( Edited 2018-04-02 14:09)

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.

P#51187 2018-04-02 12:07 ( Edited 2018-04-02 16:07)

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.

P#51202 2018-04-02 13:42 ( Edited 2018-04-02 17:46)

Got it - though I never had this use case in my previous games.

P#51221 2018-04-02 17:06 ( Edited 2018-04-02 21:06)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-18 13:50:37 | 0.009s | Q:14