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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"url": "<url>"
},
"name": "cocos_read_preview_state"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| expression | No | window.game | |
| wait_ms | No | ||
| viewport_width | No | ||
| viewport_height | No | ||
| timeout_ms | No |