|
Post by eyfenna on Jul 28, 2019 12:45:52 GMT -6
I don't get how ReadInput_Text$() works, I started the process with ReadInput_Start() and then loaded a string variable with the outcome of ReadInput_Text$() and print it out with fprint. However console stays empty. In so far I think I missed a hint.
|
|
|
Post by tbird on Jul 28, 2019 15:53:11 GMT -6
WindowOpen(0, "Text Test", 0, 0, 800, 600, 0) CanvasOpen(0, 800, 600, 0, 0, 800, 600, 1) Canvas(0) LoadFont(1, "Adler.ttf", 36) SetColor(RGB(20, 255, 50)) DIM userInput$ ReadInput_ToggleBackspace(True) ReadInput_Start() While NOT Key(K_ESCAPE) ClearCanvas() userInput$ = ReadInput_Text() DrawText("UserInput: " + userInput$, 100, 50) DrawText("Hit 'Ctrl' + 'R' to reset text.", 100, 100) If (Key(K_LCTRL) And Key(K_R)) Or (Key(K_RCTRL) And Key(K_R)) Then ReadInput_SetText("") 'Here you can set the text to say, an incoming message. End If Update() Wend
Adler.ttf (52.44 KB) Hope this helps
|
|
|
Post by eyfenna on Jul 28, 2019 20:15:46 GMT -6
Thanks a lot tbird,
I was trying to increase this example with a way to store a lot of singel words:
DIM userInput$ DIM FInput$[500, 75] DIM wordnum DIM linenum
SUB drawFormatedText() DIM currentPos DIM currentLine FOR i = 0 to 499 FOR j = 0 to 74 DrawText(FInput[i, j], currentPos*8, currentLine*16) currentPos = currentPos + length(FormatedInput[i,j]) NEXT currentLine = currentLine*16 NEXT END SUB WindowOpen(0, "Text Test", 0, 0, 800, 600, 0) CanvasOpen(0, 800, 6000, 0, 0, 800, 600, 1) Canvas(0) LoadFont(1, "Adler.ttf", 14) SetColor(RGB(20, 255, 50))
ReadInput_Start() While NOT Key(K_ESCAPE) ClearCanvas() userInput = ReadInput_Text() FInput[linenum, wordnum] = userInput drawFormatedText() IF(Key(K_SPACE)) then wordnum = wordnum +1 ReadInput_SetText ( "" ) END IF IF(Key(K_ENTER)) then linenum = linenum +1 ReadInput_SetText ( "" ) END IF Update() Wend
however the build program says Invalid Variable Definition in line 2. Sort of not clear why
|
|
|
Post by n00b on Jul 28, 2019 21:18:29 GMT -6
eyfenna FPRINT is a built-in function.
|
|
|
Post by tbird on Jul 29, 2019 8:51:00 GMT -6
eyfenna just curious, I don't really understand what your end game is here. I am asking because there would be a couple different ways I would do this depending on what your going for. As in are you just storing them up in memory, is this for a game, are you saving them to a file, are you mixing the words up or ordering them alphabetically? As I said just curious. As for your code the first couple issues I see are: SUB drawFormatedText() DIM currentPos DIM currentLine FOR i = 0 to 499 FOR j = 0 to 74 DrawText(FInput[i, j], currentPos*8, currentLine*16) <---Here you are attempting to Draw 'NULL' text currentPos = currentPos + length(FormatedInput[i,j]) <---Is this supposed to be FInput[]? NEXT currentLine = currentLine*16 NEXT END SUB The DrawText Function should be led by If statement to make sure your not entering a Null value
If Length(FInput[i, j] <> "" Then DrawText(FInput[i, j], currentPos*8, currentLine*16) End If Also the Key(K_ENTER) should be Key(K_RETURN)
I am going to try and run it and report back.
Well I got it working...but not working I don't think that is how its supposed to be behave.
DIM userInput$ DIM FInput$[500, 75] DIM wordnum DIM linenum SUB drawFormatedText() DIM currentPos DIM currentLine FOR i = 0 to 499 FOR j = 0 to 74 If Length(FInput[i,j]) Then DrawText(FInput[i, j], currentPos*8, currentLine*16) currentPos = currentPos + length(FInput[i,j]) End If NEXT currentLine = currentLine*16 NEXT END SUB WindowOpen(0, "Text Test", 0, 0, 800, 600, 0) CanvasOpen(0, 800, 6000, 0, 0, 800, 600, 1) Canvas(0) LoadFont(1, "Adler.ttf", 14) SetColor(RGB(20, 255, 50)) ReadInput_Start() While NOT Key(K_ESCAPE) ClearCanvas() userInput = ReadInput_Text() FInput[linenum, wordnum] = userInput drawFormatedText() IF Key(K_SPACE) then wordnum = wordnum +1 ReadInput_SetText ( "" ) END IF IF Key(K_RETURN) then linenum = linenum +1 ReadInput_SetText ( "" ) END IF Update() Wend More info please! lol
|
|
|
Post by eyfenna on Jul 29, 2019 11:56:12 GMT -6
eyfenna just curious, I don't really understand what your end game is here. I am asking because there would be a couple different ways I would do this depending on what your going for. As in are you just storing them up in memory, is this for a game, are you saving them to a file, are you mixing the words up or ordering them alphabetically? As I said just curious. Heya tbird,
thanks very much for correcting the code. It indeed does work now as I wanted to know.
most basically I'm going for learning the behaviour of the functions. Main question was could I write a longer text in a texteditor like style, well I found out with this program not so much as the lines align in a for me weird looking way.
Additional storing each singel word in an array cell and drawing them one by one seems runtime wise suboptimal when it comes to longer texts.
|
|
|
Post by tbird on Jul 30, 2019 6:11:17 GMT -6
Ah ok, that clears things up!
|
|