cocos_read_preview_state
Retrieve runtime game state values from Cocos Creator preview by evaluating JavaScript expressions against exposed window objects.
Instructions
Evaluate a JavaScript expression against the running preview and return the value.
The preview page must expose state on window for this to be
useful — the pattern is window.game = this inside a
GameManager's onLoad. Then you can read window.game.score,
cc.director.getScene().name, etc.
Returns {ok, value, error}. On a JS exception, ok=False
and error carries the message — a bad expression can't
crash the tool.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| expression | No | window.game | |
| wait_ms | No | ||
| viewport_width | No | ||
| viewport_height | No | ||
| timeout_ms | No |