Skip to content

stop ​

Stop and send a hide message ​

stop: is used to stop the mini game. Unlike the parameterless stop, this method allows sending a final "hide message" to the game script while stopping the engine logic. This is typically used to notify the game of the current exit reason, save the last business state, or trigger the game's internal cleanup logic.


Method Declaration ​

objectivec
/**
 * Stop the mini game and send a message.
 * @param onHideMsg The final message string passed through to the game on stop (JSON format recommended).
 * This message is captured in the game's `onHide` lifecycle or destroy callback.
 */
- (void)stop:(nullable NSString *)onHideMsg;

Parameters ​

ParameterTypeRequiredDescription
onHideMsgNSStringNoStop message: contains parameters such as reason (exit reason), lastScore (final score). If no parameters are needed, pass nil or "{}".

Runtime Behavior ​

  1. Final notice: Before the engine fully shuts down, onHideMsg is dispatched to the JavaScript layer first.
  2. Lifecycle trigger: Triggers the game's internal onHide callback; the game can perform final saving or resource release based on the incoming JSON string.
  3. Engine suspension: After the message is dispatched, the JavaScript virtual machine stops running immediately.
  4. State transition: The state falls back from SUD_RT_GAME_STATE_PLAYING (3) or SUD_RT_GAME_STATE_RUNNING (2) to SUD_RT_GAME_STATE_WAITING (1).

Example ​

Called when the user is kicked out of a room or runs out of balance, to tell the game the exit reason:

objectivec
// 1. Build the business parameters for stopping
NSDictionary *stopParams = @{
    @"reason": @"room_closed",
    @"save_state": @(YES)
};

// 2. Convert to a JSON string
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:stopParams options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

// 3. Stop (Selector: stop:)
[self.gameHandle stop:jsonString];

NSLog(@"[SUD] Game stop instruction sent with the exit reason.");

Notes ​

  • Async execution: After calling this method, the engine does its best to ensure the message reaches the JavaScript layer, but if the script has already crashed or is in an infinite loop, the message may not be processed.
  • State reset: After calling stop:, all game rendering and timers stop. To start again, you must call start: again.
  • Resource retention: This method does not destroy the gameHandle instance; the engine environment remains in memory.
  • Name matching: Note that in Objective-C, the full Selector of this method is stop: (with a colon), which is a different entry point from the parameterless stop.