New games every week!
JSE - New String+Array Commands Blog
12th June 2021
Having one of those days where writing your own language is infinitely easier than trying to get anything to work in Nintendo's newest Game Builder Garage!

-=-=-

Graphics 512,512,1 ResetDraw() Txt="Hello World" Repeat CLS 30,30,80 w=Limit(Abs(MouseX()-256),3,256)*2 h=Limit(Abs(MouseY()-256),3,256)*2 SetCol 80,60,30; Rect 256,256,w,h,1 SetFontSize_Fit Txt,w,h SetCol 150,120,80; Text 256,256,Txt,1 Flip Forever


There's now a SetFontSize_Fit(String, Width, Height) command, which will return and set the font-size to an approximate font size to fit the text snuggly within the rectangular area.
You might want to check the font size being returned, and .. if it's "too" small, reformat the string to be a couple of lines or something.

Other new commands.

Strings


TextWidth(String) and TextHeight(String) return the width and height in pixels for the string using the current font size, and taking Width and Height into account.

Trim(String) returns a trimmed version of the string, removing spaces from either side.
Shuffle(String) returns a version of the string with all the characters shuffled into a random order.
Reverse(String) returns the string with all the characters backwards.
Sort(String,Order) returns all the characters in ASCII order, where 0 = low to high, or 1 = high to low.

Arrays



ShuffleArray(Array), ReverseArray(Array) and SortArray(Array) work the same as their string versions.
Note that, currently, these only work for Single-Dimension arrays. I need to wrap my head around the best way to do this for multi-dim arrays!! Complicated stuff!!

EmptyArray(Array, Value=0) Resets every value in the array to 0. You can also specify a value and have that be used, instead.

Numbers



SHL and SHR (or << and >>) perform bitshifting functionality, moving binary bits left or right by the required amounts.

SmoothTo(a,b) is used to smoothly move value B towards A.
An optional third parameter defines the smoothness, and a fourth value is the minimal distance they can be apart, before A=B.
Essentially, this is my favourite function A=A-((A-B)/C), wrapped into a command.

Graphics 512,512,2 Dim Pos(10,2) For n=1 to 8 Pos(n,1)=256 Pos(n,2)=256 Next Repeat CLS For n=1 to 8 if MouseX()>-1 Pos(n,1)=SmoothTo(Pos(n,1),MouseX(),n*4) Pos(n,2)=SmoothTo(Pos(n,2),MouseY(),n*4) endif Text Pos(n,1),Pos(n,2),n*4,1 Next Flip Forever


..
I think that's everything!!
Views 138, Upvotes 21  
Jse , New Commands
New games every week!
Site credits : This was all done by Jayenkai
(c) Jayenkai 2023 and onwards, RSS feed 4

Blog - JSE - New String+Array Commands - AGameAWeek