Skip to content

Script functions

Mick edited this page Aug 17, 2017 · 8 revisions

Provided functions in MonkeyKing script.

Useful information:

Data type:

  • float: python builtin float type
  • int: python builtin int type
  • str: python builtin string
  • bool: python builtin boolean
  • position: A tuple of int eg, (100, 240) or a position ID in config file.
  • pointer: A checkpoint name in string or a line number.

Branch Flag:

A branch flag is a bool variable that is shared over the whole program. You can only set it to be True or False by branch-screen function. Its main function is to work together with conditional jump functions to manipulate script flow.


All functions:

wait-screen

Tell monkey king to wait the target screen appears. Check by screen image comparison.

Usage: wait-screen <screenId> <maxAttempt> <interval> <threshold> <optional>

Parameters:

  • screenId(str), Screen ID in config, Default: None
  • maxAttempt(int), Max attempt count, Default: DEFAULTS['waitUntilScreenMaxAttempt']
  • interval(int), Time wait between attempt, Default: DEFAULTS['waitUntilScreenInterval']
  • threshold(float), Percentage of match with current screen and Screen ID, Default: DEFAULTS['checkScreenThreshold']
  • optional(bool), If this step failed will stop further automation if not optional, Default: False

branch-screen

Mark branch flag to be True or False with check by screen image comparison.

Usage: branch-screen <screenId> <threshold>

Parameters:

  • screenId(str), Screen ID in config, Default: None
  • threshold(float), Percentage of match with current screen and Screen ID, Default: DEFAULTS['checkScreenThreshold']

tap-until-screen

Tell monkey king to tap on (DEFAULTS['screenCenter']) to pass screen until target screen appears. Check by screen image comparison.

Usage: tap-until-screen <screenId> <maxTap> <interval> <threshold> <optional>

Parameters:

  • screenId(str), Screen ID in config, Default: None
  • maxTap(int), Maximum tap attempt before screen appears, Default: DEFAULTS['waitUntilScreenMaxAttempt']
  • interval(int), Time wait between tap attempt, Default: DEFAULTS['waitUntilScreenInterval']
  • threshold(float), Percentage of match with current screen and Screen ID, Default: DEFAULTS['checkScreenThreshold']
  • optional(bool), If this step failed will stop further automation if not optional, Default: False

pass-screen

Tell monkey king to tap on screen position to pass target screen. Check by screen image comparison.

Usage: pass-screen <screenId> <maxAttempt> <interval> <threshold> <position> <optional>

Parameters:

  • screenId(str), Screen ID in config, Default: None
  • maxAttempt(int), Max attempt count, Default: DEFAULTS['waitUntilScreenMaxAttempt']
  • interval(int), Time wait between attempt, Default: DEFAULTS['waitUntilScreenInterval']
  • threshold(float), Percentage of match with current screen and Screen ID, Default: DEFAULTS['checkScreenThreshold']
  • position(position), Tap position on screen, Default: Use position ID "pass-{screenID}" or None if position ID is not present in config
  • optional(bool), If this step failed will stop further automation if not optional, Default: False

sleep

Tell monkey king to wait an amount of time.

Usage: sleep <duration>

Parameters:

  • duration(float), Time in float, Default: 0

shell

Tell monkey king to run a command on device.

Usage: shell <cmd>

Parameters:

  • cmd(str), Command string, Defulat: ''

tap

Tell monkey king to tap on a position.

Usage: tap <position>

Parameters:

  • position(position), Tap position on screen, Default: None

hold

Tell monkey king to hold touch on a screen position.

Usage: hold <position>

Parameters:

  • position(position), Hold position on screen, Default: None

release

Tell monkey king to release hold touch event.

Usage: release

No parameters.

drag

Tell monkey king to perform drag gesture on screen.

Usage: drag <from> <to> <duration>

Parameters:

  • from(position), Start position, Default: None
  • to(position), End position, Default: None
  • duration(float), Time will be used to move from start position to end position, Default: 0

press

Tell monkey king to press a key. Code reference from https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU

Usage: press <keyCode>

Parameters:

  • keyCode(str), Key code to be pressed, Default: None

input-text

Tell monkey king to type a string.

Usage: input-text <text>

Parameters:

  • text(str), String content, Default: ''

bootup

Start the game or go back the game.

Usage: bootup

No parameters.

shutdown

Close the game.

Usage: shutdown

No parameters.

desktop

Go to desktop screen.

Usage: desktop

No parameters.

backup-game

Save related files in the game folder to your computer. This will use config file.

Usage: backup-game

No parameters.

reset-game

Reset the game start from beginning. This will use config.

Usage: reset-game

No parameters.

jump

Tell monkey king to jump to target script label line or a line number.

Usage: jump <target>

Parameters:

  • target(pointer), Go to target line, Default: None

jump-true

Tell monkey king to jump to target script checkpoint line or a line number if branch flag is True.

Usage: jump-true <target>

Parameters:

  • target(pointer), Go to target line, Default: None

jump-false

Tell monkey king to jump to target script checkpoint line or a line number if branch flag is False.

Usage: jump-false <target>

Parameters:

  • target(pointer), Go to target line, Default: None

checkpoint

Mark current line to be checkpoint with an unique name. Uses for jump functions.

Usage: checkpoint <id>

Parameters:

  • id(str), Checkpoint name, Default: None

exit

Terminate whole program.

Usage: exit <message>

Parameters:

  • message(str), Display message, Default: 'No info'

save-snapshot

Save current screen to a file.

Usage: save-snapshot

No parameters.

save-result-screen

Usage: save-result-screen

No parameters.