hBasic > hManual > Functions

hBasic Manual
Function changes

Convert


DEVICE$ (..) Gets specific device information as a string

INT    ( nexp | sexp ) accepts a string

INT$  ( nexp | sexp ) accepts a string
Extract


ROUND (..)
Fix for ROUND function for precise input values

VERSION$ (..)
return base version

WORD_ALL$ ( .. )
Does not trim leading and trailing empty words
Graphics



GR_CONTAINS ( .. )
GR_TWEENS (..)
Does object contain a coordinate ?
return number of active tweens

INT (..) and INT$ (..)

These functions now accept a string as well as a number.

INT   (nexp | sexp)        % convert to real + dismiss fractional part
INT$ (nexp | sexp)        % convert to string + truncate fractional part

e.g
s$ = "99.12"
PRINT INT(s$)       % 99.0
PRINT INT$(s$)      % 99

DEVICE$ ()

DEVICE$ ( <key_sexp> )

Gets device information without needing permissions.
This function is an alternative to the legacy DEVICE sub-commands

Pass a key_sexp to get information about the key.
e.g
a$ = DEVICE$("locale")    % will return e.g "en_US"
The allowed keys are;
Key example
comment
"LANGUAGE" "English"     Language
"LOCALE" "en_US" Locale
"OS" "4.0.3" Android version
"BATT_PERCENT" "73" battery level as percentage left.
"BATT_STATUS" "Discharging" "Charging", "Not Charging", "Discharging", "Full","Unknown"
"ORIENT_SIMPLE"
"Portrait"
"Portrait", "Lansdscape"
All keys are case-insensitive.

Notes: Returned value is a string. You may have to use IS_NUMBER and VAL to parse it for a number.
(This function is similar /but not the same/ as the legacy DEVICE and  sub commands).
Some items are not part of the legacy DEVICE command and will not show up in it's bundles or strings.

ORIENT_SIMPLE
Returns the last view orientation as simply "Portrait" or "Landscape". This is the last config set for the top most view and might not be the same as the last requested orientation - depending on what is allowed by the hardware. It is mainly used with OnORIENT ..ORIENT.Resume.

VERSION$(0)

VERSION$()
returns the app version
VERSION$(0)         
returns a base version

This command returns a version string.
e.g
PRINT VERSION$()
PRINT VERSION$(0)

04.30
02.14


The current version of hBasic e.g 04.30 is equal to the master version with almost ALL patches applied.

The master version e.g 02.14 is the code base version used to build hBasic. This is the master shipped with hSuite. If you apply all patches within hSuite amd compile, you have the equivalent of the current version.

Both version numbers are user-definable within the hSuite compiler.
So if you are making a standalone APK with hSuite, they will reflect the version numbers that you type in for your app.
If you don't use hSuite, your app maker will have to change the versions itself internally.

WORD_ALL$ ( .. )

WORD_ALL$ (source_sexp, nth_nexp {, separator_sexp})
Same as WORD$ except that it will not trim leading and trailing empty words.
This is useful for empty data in specific columns.

e.g
s$ = ",,1,2,3,,"              % get the 3rd word/column
PRINT WORD$ (s$,3,",")        % 3
PRINT WORD_ALL$ (s$,3,",")    % 1

ROUND (..)

Fix for ROUND function for precise input values

The math function ROUND (<value_nexp>{, <count_nexp>{, <mode_sexp>}})
..was using java BigDecimal for rounding BUT the input values were still binary64 leading to precision errors.
This was fixed internally to first convert to a string.
GR_CONTAINS (..)

GR_CONTAINS (objPtr_nexp, x_nexp ,y_nexp)

Does object contain X,Y ?
Returns true if object given by object number objPtr contains coordinate x,y. Otherwise returns false.
e.g this can be used after GR.TOUCH to test if an object was touched.

GR_TWEENS (..)

GR_TWEENS ()
GR_TWEENS ( { < obj_nexp | arr[]_nexp > } {, parameter_sexp ) {, all_lexp )

Counts the number of Tweens (that have not expired).
The function is useful for determining if a tweens have expired (or not). Expired tween are always removed.

The first form returns the total number of tweens of all objects in the display list.
Objects not on the display list are ignored.

The second form  returns the number of tweens matching the object , parameter pair.
If either the obj or parameter are omitted, then it is treated as a wildcard.
Both obj and parameter are optional. A comma is needed for parameter.

The all argument is for advanced usage where the user has manipulated the display list.
If the optional argument all is omitted or false (default), then only the tweens in the display list are counted.
If the all argument is true, then all objects in the objects list are counted.

The rules for  arrarys and groups are the same as GR.TWEEN.ADD.

Examples

PRINT GR_TWEENS()             % number of tweens on display
PRINT GR_TWEENS(,,1)         % all tweens, even if not on display list

PRINT GR_TWEENS(oCircle)     % number of tweens for object circle
PRINT GR_TWEENS(,"alpha")    % all alpha tweens
PRINT GR_TWEENS(,"alpha",1)  % all alpha tweens, even if not on display