Nivekk / KOS

Fully programmable autopilot mod for KSP.
Other
80 stars 30 forks source link

Off screen printing checking. Take 2 #125

Open a1270 opened 10 years ago

a1270 commented 10 years ago

Totally messed up my local branch rebaseing and was too lazy to unbreak it. Printing off screen causes a out of array exception(flagrant error). Sorry about the indenting, Monodevelop seems hardset in its ways. This is what i am using to test.

clearscreen. set lineNum to 0. set orbit to 0. until orbit == 1 { print "LineNum: " + lineNum at (2,2). print "test" at (10,lineNum). on ag5 break. set lineNum to lineNum+1. }

Dunbaratu commented 10 years ago

What should be the proper behavior when the print-at goes past the edge of the screen? I could see two possible approaches:

1 - The excess is truncated. Quick to implement, but a bit incorrect.

2 - The excess wraps around to the next line and behaves like any normal print, including scrolling up if it's the last line of the screen. Obviously this should be treated with a bit of recursion (so it also handles strings longer than 2 lines, or longer than 3, etc), So if you try to print string S that's, say, L characters long starting at position M,N on a screen that's got a width of W, you'd get some logic like this:

Cut S into two strings: s1 is the subset consisting of the first (1+ (W - M)) number of characters, or just the entire string if it's not that long. s2 is the remainder of the string after s1 is removed from it, or null string if it's short enough not to have excess. Print s1 at the intended location (M,N). recursively call myself to print s2 at location (0,N+1).

a1270 commented 10 years ago

I was looking into line wrapping but got sidetracked. I had some very basic code to do it in the second way but it's missing. I'll see if i can get some gears turning and rewrite it.