Skip to content

Updating Scores

Proper score tracking is essential for accurate game state management. This includes initializing scores, updating them during gameplay, and optionally tracking score sources.

Before Scoring

Before recording actual scores, it's important to initialize player scores to zero. This helps establish the game session and player order.

void initialize_player_scores(sb_game_handle_t state, int num_players) {
    // Initialize each player with zero score
    for (int player = 1; player <= num_players; player++) {
        sb_set_score(state, player, 0, 0);
    }

    // Commit the initial scores
    sb_commit(state);
}
void initialize_player_scores(scorbit::GameState& gs, int num_players) {
    // Initialize each player with zero score
    for (int player = 1; player <= num_players; player++) {
        gs.setScore(player, 0);
    }

    // Commit the initial scores
    gs.commit();
}
def initialize_player_scores(gs, num_players):
    # Initialize each player with zero score
    for player in range(1, num_players + 1):
        gs.set_score(player, 0)

    # Commit the initial scores
    gs.commit()

Zero Score Importance

Always initialize players with zero scores, even if they haven't played yet. This establishes the player count and order for the session.

Score Updates

You can update scores for single or multiple players during gameplay.

Single Player Update

void update_player_score(sb_game_handle_t state, sb_player_t player, sb_score_t score) {
    // Update score
    sb_set_score(state, player, score, 0);

    // Commit the score update
    sb_commit(state);
}
void update_player_score(scorbit::GameState& gs, int player, sb_score_t score) {
    // Update score
    gs.setScore(player, score);

    // Commit the score update
    gs.commit();
}
def update_player_score(gs, player, score):
    # Update score
    gs.set_score(player, score)

    # Commit the score update
    gs.commit()

Multiple Player Updates

void update_all_scores(sb_game_handle_t state, sb_player_t p1_score, sb_player_t p2_score) {
    // Update scores for all active players
    sb_set_score(state, 1, p1_score, 0);
    sb_set_score(state, 2, p2_score, 0);

    // Single commit for all updates
    sb_commit(state);
}
void update_all_scores(scorbit::GameState& gs, sb_score_t p1_score, sb_score_t p2_score) {
    // Update scores for all active players
    gs.setScore(1, p1_score);
    gs.setScore(2, p2_score);

    // Single commit for all updates
    gs.commit();
}
def update_all_scores(gs, p1_score, p2_score):
    # Update scores for all active players
    gs.set_score(1, p1_score)
    gs.set_score(2, p2_score)

    # Single commit for all updates
    gs.commit()

Score Features

Available Feature Types

The feature parameter in setScore/sb_set_score can be one of the following values:

Feature Constant Value Description
SB_FEATURE_NONE 0 No specific feature (default)
SB_FEATURE_RAMP 1 Points from ramp shots
SB_FEATURE_SPINNER 2 Points from spinner hits
SB_FEATURE_TARGET 3 Points from target hits
SB_FEATURE_SWITCH 4 Points from switch hits
SB_FEATURE_JACKPOT 5 Regular jackpot awards
SB_FEATURE_SUPER_JACKPOT 6 Super jackpot awards
SB_FEATURE_MODE_COMPLETE 7 Mode completion bonuses
SB_FEATURE_MULTIPLIER 8 Multiplier-based points
SB_FEATURE_SKILL_SHOT 9 Skill shot awards
SB_FEATURE_COMBO 10 Combo shot awards
SB_FEATURE_MODE_START 11 Mode start awards
SB_FEATURE_WIZARD 12 Wizard mode points

Example Usage

// Example using feature types
sb_set_score(state, player, 1000000, SB_FEATURE_JACKPOT);  // Jackpot award
sb_set_score(state, player, 500, SB_FEATURE_NONE);         // Regular points
// Example using feature types
gs.setScore(player, 1000000, scorbit::ScoreFeature::Jackpot);  // Jackpot award
gs.setScore(player, 500, scorbit::ScoreFeature::None);         // Regular points
# Example using feature types
gs.set_score(player, 1000000, scorbit.ScoreFeature.JACKPOT)  # Jackpot award
gs.set_score(player, 500, scorbit.ScoreFeature.NONE)         # Regular points

Default Feature

If no feature is specified, SB_FEATURE_NONE (0) is used.

Feature Selection

Choose the most specific feature type that applies to help with score analysis.

Score Types

Scores can be tagged with feature identifiers to track their source. This helps with analytics and gameplay insights. Next to the score, you can also add a feature identifier. These are not meant to replace targets or modes, but to add more context to a specific score increase only.

void update_feature_score(sb_game_handle_t state, sb_player_t player, 
                        sb_score_t score, sb_score_feature_t feature) {
    // Add points with feature identifier
    sb_set_score(state, player, score, feature);

    // Commit the feature score
    sb_commit(state);
}
void update_feature_score(scorbit::GameState& gs, int player, 
                        sb_score_t score, sb_score_feature_t feature) {
    // Add points with feature identifier
    gs.setScore(player, score, feature);

    // Commit the feature score
    gs.commit();
}
def update_feature_score(gs, player, score, feature):
    # Add points with feature identifier
    gs.set_score(player, score, feature)

    # Commit the feature score
    gs.commit()

Common Score Types

Type Example Score Code Example
Ramps Right Ramp 800 sb_set_score(state, player, 800, SB_FEATURE_RAMP)
Spinners Super Spinner 7,000 sb_set_score(state, player, 7000, SB_FEATURE_SPINNER)
Targets Left Target 1,000 sb_set_score(state, player, 1000, SB_FEATURE_TARGET)
Named Switches Left Outlane 25,000 sb_set_score(state, player, 25000, SB_FEATURE_SWITCH)
Jackpots Lightcycle Jackpot 100,000 sb_set_score(state, player, 100000, SB_FEATURE_JACKPOT)
Super Jackpots Wizard Jackpot 2,000,000 sb_set_score(state, player, 2000000, SB_FEATURE_SUPER_JACKPOT)
Mode Completion Metamorphosis 1,000,000 sb_set_score(state, player, 1000000, SB_FEATURE_MODE_COMPLETE)
Multiplier Bonus 2X 1,000 sb_set_score(state, player, 1000, SB_FEATURE_MULTIPLIER)
Skill Shot Snake Charmed 100,000 sb_set_score(state, player, 100000, SB_FEATURE_SKILL_SHOT)
Loop Combos 3-Way 2,500,000 sb_set_score(state, player, 2500000, SB_FEATURE_COMBO)
Mode Starts Tiger Saw 5,000 sb_set_score(state, player, 5000, SB_FEATURE_MODE_START)
Wizard Mode Grande Finale 150,000,000 sb_set_score(state, player, 150000000, SB_FEATURE_WIZARD)

Feature Usage

Using score features consistently can enable better gameplay analysis and player statistics.

Score Accuracy

Always verify that score updates are properly committed before proceeding with gameplay.

Commit Frequency

While you should commit after score changes, batch multiple updates into a single commit when possible.

Ball Updates

You can update the current ball number during gameplay:

void update_ball(sb_game_handle_t state, int ball) {
    // Update current ball number
    sb_set_current_ball(state, ball);

    // Commit the update
    sb_commit(state);
}
void updateBall(scorbit::GameState& gs, int ball) {
    // Update current ball number
    gs.setCurrentBall(ball);

    // Commit the update
    gs.commit();
}
def update_ball(gs, ball):
    # Update current ball number
    gs.set_current_ball(ball)

    # Commit the update
    gs.commit()

Ball Numbers

  • Ball numbers typically start at 1
  • Update the ball number before scoring begins for that ball
  • Extra balls should still increment the ball number

Combined Score and Ball Updates

Often you'll want to update both scores and the current ball in the same cycle:

void update_game_state(sb_game_handle_t state, int ball, sb_player_t player, sb_score_t score) {
    // Update current ball
    sb_set_current_ball(state, ball);

    // Update player score
    sb_set_score(state, player, score, 0);

    // Single commit for all updates
    sb_commit(state);
}
void updateGameState(scorbit::GameState& gs, int ball, int player, sb_score_t score) {
    // Update current ball
    gs.setCurrentBall(ball);

    // Update player score
    gs.setScore(player, score);

    // Single commit for all updates
    gs.commit();
}
def update_game_state(gs, ball, player, score):
    # Update current ball
    gs.set_current_ball(ball)

    # Update player score
    gs.set_score(player, score)

    # Single commit for all updates
    gs.commit()

Commit Frequency

Group related updates (like ball and score changes) into a single commit when possible.

Best Practices

1. Score Initialization

  • Always start with zero scores
  • Initialize all players at game start
  • Commit initial scores immediately
  • Verify player count is correct

2. Score Updates

  • Update scores promptly
  • Use appropriate feature tags
  • Batch multiple updates when possible
  • Verify score changes are committed

3. Error Handling

  • Check for valid player numbers
  • Verify score changes are reasonable
  • Handle connection issues gracefully
  • Log unusual score patterns