Search form

You are here

Hollywood Code Snippets

Submitted by djrikki on Thu, 2012-04-26 02:36

Blog Rate

up

45%

down

55%

Hello again readers,
In this blog I present to you a few code snippets I have written in Hollywood for various projects that I have been involved in, you are free to use them in any of your own projects; all I ask is that perhaps you give me a mention in the credits of your program somewhere.
These snippets might be useful for adapting into other programming languages especially some of the more mundane functions such as base:SecsToHMS() which will be our first code snippet.
As with all these base:library snippets below your Hollywood program needs to declare the following somewhere in the top-level of your code before being called.

Global base

base ={}

You should also use the following code in your Hollywood projects as they can be very useful to you.

Global application

application ={}

application.debug= False

application.debugtofile= False

application.version="1.0"

application.platform= GetVersion().platform

Local t = GetFileAttributes("PROGDIR:TheNameOfYourExecutableProgram")

application.path= PathPart(t.path); the full path to your executable, useful if you need to specify it in Execute() or Run()- better than forcing an unnecessary Assign: on the end-user.

application.screenwidth= GetAttribute(#DISPLAY, 0, #ATTRHOSTWIDTH)

application.screenheight= GetAttribute(#DISPLAY, 0, #ATTRHOSTHEIGHT)

; Convert seconds into Hours, Minutes and Seconds

Function base:SecsToHMS(s)

Local h, m

h=Int(s/3600)

s=s-(h*3600)

m=Int(s/60)

s=Int(s-(m*60))

Return(h, m, s)

EndFunction

; Convert a given filesize in bytes into written notation eg;1.1 TB,10.5 GB,11 MB,309 KB,90 bytes

I use base:SystemRequest() in several of these snippets mentioned in this blog. This particular function strips away any Hollywood square bracket underlining you might supply it in the 'title' argument. Foreinstance this is useful if you want to have labelled buttons on-screen where one letter is underlined to provide keyboard support- you never know when you might have to show that label within a system requester at some point in the future.

; please remove all spaces from the [ u ] and [/ u] searchstring, this was

; add so the forum could display the strings correctly

If FindStr(gadgets$," [ u ]")>-1

gadgets$ = ReplaceStr(gadgets$," [ u ]","")

EndIf

If FindStr(gadgets$,"[ / u ]")>-1

gadgets$ = ReplaceStr(gadgets$,"[ / u]","")

EndIf

Return (gadgets$)

EndFunction

The base:CheckLibrary functions accepts 3 arguments, the name of the AmigaOS library to check exists, if it doesn't exist you can warn the user by setting 'warn' to True and/or you can set 'appquit' to True if you want the application to quit as a result of the library not being found.

Deleting a file can be a common practise in any program, this code snippet is a replacement for the standard DeleteFile() command. This will check the file exists first before attempting to delete it. Just because a file exists doesn't always mean that your program can just go ahead and delete it, sometimes the file might be locked. Normally if you try and delete a locked file your program will exit complaining. base:DeleteFile will ensure that even if the file is locked your program will still continue. However please bare in mind if the file is locked, it will still remain on disk.

Function base:DeleteFile(filename$)

Local err

ExitOnError(False)

If Exists(filename$)= True

err = False

DeleteFile(filename$)

Else

err = True

EndIf

ExitOnError(True)

Return (err)

EndFunction

A replacement for IsOnline() making use of base:SystemRequest to warn the user if a connection isn't found.

Global locale

locale ={}

locale[0]="OK"

locale[1]="body text of the error message to display to the user"

; This will detect if an internet connection is found and returntrue or false.

; It will also display a warning message, the argument required is for the window

This is just the tip of the iceberg. If you want to see some more, including function to develop AmigaOS-like applications complete with buttons, icon bars, option boxes and other event handling, please download the following archive from OS4Depot:
http://www.os4depot.net/share/development/example/hw_app_template.lha
The archive is a little out of date, but contains a whole host of base functions that you might want to explore and make some use of.
Thanks for reading.