start
Start the game logic
start: is the core trigger of the mini game lifecycle. After executing create and configuring the relevant start options, calling this method officially loads the game script, initializes the rendering context, and sends the first business instruction to the game (usually a message to enter a specific room or show a specific interface).
Method Declaration
objectivec
/**
* Start the mini game engine.
* @param onShowMsg The initial message string passed through to the game at startup (JSON format recommended).
* This message is captured in the game's `onShow` lifecycle or first logic entry point.
*/
- (void)start:(nullable NSString *)onShowMsg;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| onShowMsg | NSString | No | Start message: contains business parameters such as roomID, token, role. If no parameters are needed, pass nil or "{}". |
Runtime Behavior
- Script loading: The engine starts reading the entry file and executing the JavaScript code, initializing the game world.
- Lifecycle trigger: Triggers the game's internal
onLaunchandonShowcallbacks, parsesonShowMsgand passes it in as a parameter to determine the initial interface. - State transition: After success, the game state transitions from
SUD_RT_GAME_STATE_WAITING (1)toSUD_RT_GAME_STATE_RUNNING (2). - Async preparation: After this method is triggered, resource preloading and script parsing run in parallel on background threads.
Example
Usually called after the room and user information are ready:
objectivec
// 1. Build the startup business parameters
NSDictionary *startParams = @{
@"roomId": @"123456",
@"appId": @"your_app_id"
};
// 2. Convert to a JSON string
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:startParams options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// 3. Officially start the game (Selector: start:)
[self.gameHandle start:jsonString];
NSLog(@"[SUD] Game start instruction sent, waiting for the script to run...");Notes
- State check: Before calling, make sure the
gameHandleis created and not destroyed. Calling it in theUNAVAILABLEstate will fail. - Message format: Although the parameter is an
NSString, it is strongly recommended to use standard JSON format. Non-JSON strings may cause parsing errors on the game side. - Not shown immediately:
start:only means the logic starts running. To actually render the screen and respond to touches, you usually also need to callplayafterward.
