DroidScript provides some methods and flags in the sourcecode which are not available in regular JavaScript code but are interpreted internally by DroidScript.
You don't necessarily need to use these features but they are still pretty useful in some cases.
The cfg object can be used to apply app options to your app before it is launched.
They should be placed at the very top of your main source script.
Defines the initial screen orientation your app will launch in
These settings will change the look of all your controls. Holo was the default theme until DS 1.90 beta, where cfg.Light and cfg.Dark were added and cfg.Dark became the dark theme.
Note that only Light and Dark theme can be exchanged securely, Holo might cause broken UI in some cases when switching to Light or Dark.
Runs the app in NodeJS mode.
Enables builtin material component support through the MUI object.
The Game configuration will let your app immediately run in GameView mode. This way you can write your game code directly in the main script without bothering about creating the GameView container.
This will let your app run transparently on the HomeScreen and it will stay on top of everything even if the user launches an other app.
The Serv flag will serve any HTML or Hybrid app over a builtin HTTP server on port 3033.
This will show the console as main page instead of the GUI. Drawers will still work with this config.
The Fast config will make use of the J2V8 engine which increases the apps execution speed roughly by a factor of 3. Specifically it will increase the speed of app.* calls, which is quite useful for tween animations or when creating and modifying a huge amount of app controls.
The drawback of this method is that all default WebView DOM objects are not available any more.
This includes methods like setInterval and setTimeout which should be converted to app.Animate respectively.
Note: The same effect can be observed when running in a Node.js environment (using the cfg.Node flag)
In callback functions of controls you can use app.eventSource to access the callee control object without having to assign the control to a specific variable. Previously this could be achieved by using the this keyword. This allows you to create multiple controls with the same behaviour without having to redefine callback functions for different controls:
There are shortcuts to certain functions, which are
DW() => app.GetDisplayWidth()
DH() => app.GetDisplayHeight()
TW(
txt, size) => app.GetTextBounds(
txt, size, 0, null).width
_PlaySound(
file)
_GetRandomColor():
color
RGB(
r,
g,
b):
color
atob2():
base64 .
These methods can force DroidScript to add or remove specific permissions from your app.
See also: GetPermission, CheckPermission
Converts a keyword into the translated text using a lang.json file.
DroidScript checks if a callback function already exists and uses it instead of creating a new instance.
This can cause issues when referring to other local variables in private scopes.
Therefore you can wrap your callback functions in an I() clause to force DroidScript to create a new callback instance for that scope.
The M() macro is equivalent to the I() macro, except that it accepts a custom 'this' context as first argument.
Alternatively you can make use of the controls data property and the this keyword in callbacks.
This way you can assign variables to the object they belong to and you still make use of the callback optimization by DroidScript: