v1.1
Here is a Text system that I've been working on! Any type of feedback or criticism is welcome!
~~ PROS ~~
- Dynamic Name Tab
- Simply Formatted
- Light Weight
~~ CONS ~~
- Manually add a new line using '\n'
~~ UPDATE CHANGELOG ~~
1.1 - Dynamic name now works with special icons (Thanks @RealShadowCaster)
1.0 - Initial release
Rather than assuming every character to be 3 pixels wide, you can print the name offscreen and get print's return values to know the pixel dimensions of the print, then print onscreen based on that and add your name border accordingly. You could handle multi line names, even, if you grab both x and y return values. Not sure that extra feature would be worth the tokens, though.
About the \n in the text string, nothing stops you from using a multi line string with [[ ]] if you prefer.
And if you really want to be able to call the function multiple times to do sequences of prints in the same window, you could use currying. (the text function returns a function, so you can do text("name",line1)(line2)(line3) for example. )
Note that currying is seldom used in pico-8 because of the high token cost of calls
@0xFFFF967F , Lua has a lot of non obvious powerful features. If you tell me you developpers background, I may be able to highlight what's new for you.
For me, the biggest discovery was related to the fact that functions are basic element of the language, at the same level than numbers, boolean, arrays or nil. Things like
spr=trace(spr)
where you change the behavior of a core function felt pretty wild at first.
- Thanks for that suggestion, I'm still kind of new to this and feedback really helps!
- Multiline strings don't really work as they tends to start a new line in the middle of a word...
@noiD_on_scratch
I don't really understand what you mean about multi-line stings cutting words.
Here's what I meant :
-- main loop function _init() showtext = 1 end function _update() if btnp(0) and not(showtext==1) then showtext=showtext-1 elseif btnp(1) and not(showtext==8) then showtext=showtext+1 end end function _draw() cls() bg() if showtext==1 then text("i made a text thingy", [[it's pretty cool (⬅️➡️ to continue) v1.1]],1) elseif showtext==2 then text(nil,"it can have no name") elseif showtext==3 then text("or no 'text'",nil) elseif showtext==4 then text("✽🅾️➡️♪…◆", [[dynamic name even works with special icons! (thank you @RealShadowCaster)]]) elseif showtext==5 then text("new lines", [[the main way to add a new line is by adding '\n' when needed.]]) elseif showtext==6 then text("how it's formatted","text(name,text)") elseif showtext==7 then text("how it's formatted", [[text() is the base command. put a string where 'name' or 'text' is to add text. put nil instead to have nothing.]]) elseif showtext==8 then text("credits","better dynamic name:\n @RealShadowCaster") end --[[in name, put nil if you do not want a name modes 1 = normal ]] end |
Multi line with [[ and ]] work just fine with your text() function, and because the font is the same in the editor and in the game text, and the window size is also about the same, I find it easier to visualize what will bu shown using multi-line text. Both are fine, you just have options.
Maybe what you want is text warp so you just call your function with a long text, and the text() function takes care of the formatting ?
If so, you can use split to cut your text into words, print them offscreen to get their dimensions, and then do the actual onscreen words prints so that it fits nicely onscreen.
@RealShadowCaster
Ah, I see what you mean now, i guess its really upto preference
also, there's a split command??
After a simple test (x = split("what does this do") print(x)) I see that split splits the words into a table value, which is going to be interesting, thanks for the feedback, im learning a lot more like this then wandering in the dark lol
[Please log in to post a comment]