Skip to content

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 ​

ParameterTypeRequiredDescription
onShowMsgNSStringNoStart message: contains business parameters such as roomID, token, role. If no parameters are needed, pass nil or "{}".

Runtime Behavior ​

  1. Script loading: The engine starts reading the entry file and executing the JavaScript code, initializing the game world.
  2. Lifecycle trigger: Triggers the game's internal onLaunch and onShow callbacks, parses onShowMsg and passes it in as a parameter to determine the initial interface.
  3. State transition: After success, the game state transitions from SUD_RT_GAME_STATE_WAITING (1) to SUD_RT_GAME_STATE_RUNNING (2).
  4. 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 gameHandle is created and not destroyed. Calling it in the UNAVAILABLE state 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 call play afterward.