Skip to content

setGameStartOptions:options: ​

Set game start options (multi-parameter version) ​

setGameStartOptions:options: is used to finely configure the mini game's runtime environment across multiple dimensions before it starts. This two-parameter declaration is typically used to distinguish basic start options from extended business configuration, or to distinguish engine configuration from user-defined data.


Method Declaration ​

objectivec
/**
 * Set the game start options.
 * @param gameOptions Configuration for the engine and framework level (such as entry path, debug mode).
 * @param businessOptions Configuration for the business logic level (such as initial variables passed through to JS, channel info).
 */
- (void)setGameStartOptions:(NSDictionary *)gameOptions options:(NSDictionary *)businessOptions;

Parameters ​

ParameterTypeDescription
gameOptionsNSDictionaryEngine configuration: controls entryPath (entry), debug (debug switch), v8Flags, etc.
businessOptionsNSDictionaryBusiness configuration: injects envVars, userInfo, roomID, etc. for the game script to read directly.

Runtime Behavior ​

  1. Parameter decoupling: Separates technical-level engine parameters from business-level logic parameters, facilitating modular management.
  2. Environment warm-up: Before calling start:, these configurations are injected into the global context of the JavaScript Runtime.
  3. Persistence strategy: This setting remains in effect while the current gameHandle is active.

Example ​

objectivec
// 1. Define the engine-level configuration
NSDictionary *gameOpts = @{
    @"entryPath": @"game.js",
    @"debug": @(NO)
};

// 2. Define the business-level configuration
NSDictionary *bizOpts = @{
    @"appId": @"sud123456",
    @"subChannel": @"promotion_A",
    @"launchData": @{@"referrer": @"group_chat"}
};

// 3. Apply the configuration
[self.gameHandle setGameStartOptions:gameOpts options:bizOpts];

// 4. Then start the game
[self.gameHandle start:@"{}"];

Notes ​

  • Strict timing: Must be called after create and before start:. If called while the game is running, the parameters may not be captured by the JS script in the onLaunch lifecycle.
  • Null handling: If a part has no special configuration, you can usually pass an empty @{} dictionary, but passing nil is not recommended unless the API documentation explicitly allows it.
  • Serialization consistency: The dictionary only supports JSON-compatible data types (string, number, boolean, array, dictionary); it does not support passing native UIImage or custom object instances.