Yesterday I’ve released Helpers library v1.6, it comes with some useful examples in a single file with a handy menu to select which test/example you want to run.
Go here to download it!
I’m goin to list what’s inside the library with a brief description of each function/object.
CHECK AGAINST NIL VALUES
When Hollywood didn’t have a specific command to check if a variable was Nil (not initialized variables), I developed a simple command to do that called HL.IsNil(var) for this purpose.
Now Hollywood has its native command, which is IsNil(), that is much faster than my command, so use it in your new projects, I’m leaving my command in the library for compatibility reasons, I (and you) may have older stuff still using HL.IsNil().
There is also HL.IsNotNil() if you don’t want to do Not(HL.IsNil()), this function rexists to prettify the code and make it more readable.
MORE CONTROL ON LINEHOOK USAGE
Hollywood has two nice commands that controls the so called “Line Hook”, disabling this feature in computational loops can give a great boost to the execution speed but with some disadvantages, like for example being unable the detect events. If used with care it can improve your code speed a lot.
Since I often code using recursion I’ve found that using the standard functions EnableLineHook() and DisableLineHook() wasn’t enough so I coded my own versions that keep track of how many calls have been done and enable the line hook only when all previous calls has been all “closed”. My commands are HL.LineHook.Enable() and HL.LineHook.Disable().
A very simple usage example could be :
Function heavyCompute()
HL.LineHook.Disable()
; Do here you computes
heavyCompute() ; <- recursively call itself
anotherComputation() ; <– this should still have LineHook disabled!
HL.LineHook.Enable()
EndFunction
So, look at the above code, it just an example to let you understand what I mean, if you run it directly it will hangs forever but look at the logic: using my customized command the function anotherComputation() will be executed with Line Hook disabled, while using the standard functions, once heavyCompute() returns, the Line Hook will be enabled, and that’s wrong!
CONVERSION TOOLS & HTML STUFF
Under the HL.Convert table there some usefull convesion functions, I’m goin’ to list them all with a brief description:
- HL.Convert.BytesTo()
This function can convert any value expressed in bytes into the corresponding unit like Kilobytes, Megabytes, etc… you can specify how many decimal points you want in the output and there is also an AUTO tag so that the most appropriate unit is returned. - HL.Convert.ForTextOut()
This function help a lot with square bracket escaping. You may have noticed that when using TextOut() to print your text, it will crash if there is an unrecognized tag: for Hollywood any unrecognized tag can be just a single square bracket without any of the supported tags.
For example look at this 2 lines :
Local s = “[color=#RED]Test[/color] of something [enclosed in square brackes]”
TextOut(#LEFT, #TOP, s)
If you run it Hollywood will crash because of the square brackets on the end, you should have escaped them using this notation:
Local s = “[color=#RED]Test[/color] of something [[enclosed in square brackes]]”But you cannot always fix this easily, for example if you are handling user input, so I’ve made the forementioned function to resolve this problem: if will escape only the unrecognized tags leaving all the rest untouched, this way you can safely use TextOut() without worring about square brackets errors.
- HL.Convert.HTMLAmper2UTF8()
This function converts any supported ampersand symbol into the corresponding UTF8 printable code, of course you have to use a font that have that character defined!
Ampersands are HTML entities used to place symbols in HTML pages, for example :
⇒ is translated into ⇒
Almost all ampersands can be translated using this function (actually 761 symbols are handled). - HL.Convert.HTMLTag2HollywoodTag()
This function try to translate basic HTML tags to Hollywood tags, it just the beginning, not all tags are supported, for example it can convert the following text:
<b>here is some text</b>
into
[b]here is some text[/b]Have a look at the docs on wiki for a list of all supported tags. - HL.Convert.Unicode2UTF8()
In HTML pages you may find unicode values escaped by a double slash like this :
\u<value>
This function converts this notation to a standard UTF8 character. - HL.Convert.HTML2Hollywood()
Finally this function combines all the above functions to try to convert a very simple HTML code to a printable version using Hollywood and its TextOut() function.
Supported features are :
– Slashes, Double-Slashes, Tabs
– HTML Tags (see HL.HTML_Tags table)
– HTML Ampersands (see HL.HTML_Amper table)
– Ordered lists
– Unordered lists
Ok, it’s enough for this post, I’ll continue to describe the Helpers library the next time!
Happy Coding!