Score Scripts: Difference between revisions
No edit summary |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
[[Category:Script]] | [[Category:Script]] | ||
'''Score scripts''' are automatic | '''Score scripts''' are automatic event hooks that execute whenever OpenBOR processes a score adjustment through its native score routine. Two forms are available: numbered scripts for individual player slots and <code>scoreall.c</code> for shared project-wide handling. | ||
Numbered scripts correspond to individual players: | |||
* <code>data/scripts/score1.c</code> | * <code>data/scripts/score1.c</code> | ||
| Line 9: | Line 11: | ||
* <code>data/scripts/score4.c</code> | * <code>data/scripts/score4.c</code> | ||
Each script receives the | The shared script receives adjustments for every player: | ||
* <code>data/scripts/scoreall.c</code> | |||
Each script receives the signed 64-bit adjustment submitted to the score routine. Positive values add points, while negative values deduct them. This makes score scripts useful for custom feedback, milestones, achievements, penalties, secondary reward systems, cooperative scoring, statistics, and any other mechanic that should react immediately to native score changes. | |||
OpenBOR's score | OpenBOR's accumulated player score supports values from <code>0</code> through <code>18446744073709551615</code>. This provides enough range for extreme scoring systems, large multipliers, dense projectile bonuses, and other designs without requiring creators to split a score into manually carried pieces. | ||
Score scripts are | Score scripts are adjustment events rather than general observers of the score property. Writing a player's score directly through script does not execute them. | ||
== Usage == | == Usage == | ||
Create the desired | Create the desired score-script files in <code>data/scripts</code>. OpenBOR loads them automatically, so no model, level, or project command is required. | ||
<code>score#.c</code> is documentation shorthand in which <code>#</code> represents the player number. The literal filenames use <code>1</code> through <code>4</code>. | <code>score#.c</code> is documentation shorthand in which <code>#</code> represents the player number. The literal filenames use <code>1</code> through <code>4</code>. | ||
| Line 23: | Line 29: | ||
{| class="wikitable" | {| class="wikitable" | ||
! File | ! File | ||
! | ! Scope | ||
! Player | ! Player identification | ||
|- | |- | ||
| <code>data/scripts/score1.c</code> | | <code>data/scripts/score1.c</code> | ||
| Player 1 | | Player 1 | ||
| <code>0</code> | | Filename - index <code>0</code> | ||
|- | |- | ||
| <code>data/scripts/score2.c</code> | | <code>data/scripts/score2.c</code> | ||
| Player 2 | | Player 2 | ||
| <code>1</code> | | Filename - index <code>1</code> | ||
|- | |- | ||
| <code>data/scripts/score3.c</code> | | <code>data/scripts/score3.c</code> | ||
| Player 3 | | Player 3 | ||
| <code>2</code> | | Filename - index <code>2</code> | ||
|- | |- | ||
| <code>data/scripts/score4.c</code> | | <code>data/scripts/score4.c</code> | ||
| Player 4 | | Player 4 | ||
| <code>3</code> | | Filename - index <code>3</code> | ||
|- | |||
| <code>data/scripts/scoreall.c</code> | |||
| Every player | |||
| Local variable <code>player</code> | |||
|} | |} | ||
The | === Numbered Score Scripts === | ||
The numbered scripts receive the score adjustment. Their filename identifies the player slot. | |||
<syntaxhighlight lang="c" line> | <syntaxhighlight lang="c" line> | ||
void main() | void main() | ||
{ | { | ||
long score = getlocalvar("score"); | |||
// React to the score | // React to the score adjustment here. | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
OpenBOR does not supply <code>player</code> or <code>self</code> automatically to a numbered score script. | |||
=== Scoreall === | |||
<code>data/scripts/scoreall.c</code> is a shared listener for every player slot. It receives the zero-based player index in addition to the score adjustment. | |||
<syntaxhighlight lang="c" line> | |||
void main() | |||
{ | |||
int player = getlocalvar("player"); | |||
long score = getlocalvar("score"); | |||
// React to any player's score adjustment here. | |||
} | |||
</syntaxhighlight> | |||
<code>scoreall.c</code> allows common project-wide behavior can be written once instead of duplicated across four files. | |||
No <code>self</code> variable is supplied because the event belongs to a player slot rather than an entity. | |||
== Execution == | == Execution == | ||
The immediate score- | The immediate score-adjustment sequence is: | ||
# OpenBOR receives a player slot and | # OpenBOR receives a player slot and a signed amount to apply. | ||
# OpenBOR calculates applicable extra-life thresholds. | # OpenBOR calculates applicable extra-life thresholds. | ||
# | # Positive amounts add to the player's score and saturate at <code>18446744073709551615</code>. Negative amounts deduct from the score and saturate at <code>0</code>. | ||
# Applicable extra lives are awarded. | # Applicable extra lives are awarded. | ||
# OpenBOR stores the updated score total. | # OpenBOR stores the updated score total. | ||
# The corresponding numbered score script executes with local variable <code>score</code>. | # The corresponding numbered score script executes with local variable <code>score</code>, when present. | ||
# <code>scoreall.c</code> executes with local variables <code>player</code> and <code>score</code>, when present. | |||
The player's updated score and any extra lives from the | The player's updated score and any extra lives from the adjustment are already available when either script executes. Native processing for that individual score adjustment is otherwise complete. Negative adjustments do not remove lives that were already awarded. | ||
The numbered script always executes before <code>scoreall.c</code>. Changes made by the numbered script are therefore visible to the shared script later in the same event sequence. <code>scoreall.c</code> does not depend on the numbered file being present and still executes when no corresponding <code>score#.c</code> exists. | |||
OpenBOR may also submit an amount of zero to the score routine. Scripts | Score scripts execute once for each call to the native score routine, not once per update and not once for an accumulated group of adjustments. Stage-completion counting may therefore produce a sequence of small events as bonuses are transferred into the player's total. | ||
OpenBOR may also submit an amount of zero to the score routine. Scripts can test whether <code>score</code> is positive, negative, or zero before producing the applicable response. | |||
== Event Data == | == Event Data == | ||
| Line 78: | Line 111: | ||
! Variable | ! Variable | ||
! Type | ! Type | ||
! Available in | |||
! Description | ! Description | ||
|- | |- | ||
| <code>score</code> | | <code>score</code> | ||
| | | Signed 64-bit integer (<code>VT_INTEGER64</code>) | ||
| | | Numbered scripts and <code>scoreall.c</code> | ||
| Adjustment submitted to the native score routine. Positive values add points, and negative values deduct points. | |||
|- | |||
| <code>player</code> | |||
| Integer (<code>VT_INTEGER</code>) | |||
| <code>scoreall.c</code> only | |||
| Zero-based index of the player receiving the score adjustment. | |||
|} | |} | ||
<code>score</code> is the | <code>score</code> is the requested adjustment, not the player's new total. It is also not necessarily the actual change in the stored total. An addition that reaches the unsigned maximum or a deduction that reaches zero still supplies its original signed amount to the event. | ||
Changing the local <code>score</code> variable does not alter the | Changing the local <code>score</code> variable does not alter the adjustment or the stored player score because the event executes after native score processing. The event supplies the adjustment rather than the running total. Systems may accumulate the signed 64-bit changes in a global variable to build an independent tally, as shown below. | ||
== Score Range == | == Score Range == | ||
OpenBOR separates the signed values used to adjust score from the unsigned value used to store the player's total. | |||
{| class="wikitable" | {| class="wikitable" | ||
! Value | ! Value | ||
! Type | |||
! Minimum | |||
! Maximum | |||
|- | |- | ||
| | | Player score total | ||
| Unsigned 64-bit integer | |||
| <code>0</code> | | <code>0</code> | ||
| <code>18446744073709551615</code> | |||
|- | |- | ||
| | | Model and level score value | ||
| <code> | | Signed 64-bit integer | ||
| <code>-9223372036854775808</code> | |||
| <code>9223372036854775807</code> | |||
|- | |||
| Score-script event value | |||
| Signed 64-bit integer (<code>VT_INTEGER64</code>) | |||
| <code>-9223372036854775808</code> | |||
| <code>9223372036854775807</code> | |||
|} | |} | ||
The maximum is also known as <code>UINT64_MAX</code>, or 2<sup>64</sup> - 1. Score | The player's maximum total is also known as <code>UINT64_MAX</code>, or 2<sup>64</sup> - 1. Score adjustment uses saturation at both ends. Positive adjustments that would exceed the maximum store <code>UINT64_MAX</code>, while negative adjustments that would pass below zero store <code>0</code>. | ||
Player totals | Player totals, saved scores, and high-score entries preserve the unsigned 64-bit range. Model and level <code>score</code> commands accept signed 64-bit values, allowing creators to assign either rewards or penalties without replacing the native score system. | ||
The <code>scoreformat</code> setting continues to pad short values to nine digits. Nine digits are a minimum display width rather than a limit, so larger totals remain visible in full. | The <code>scoreformat</code> setting continues to pad short values to nine digits. Nine digits are a minimum display width rather than a limit, so larger totals remain visible in full. | ||
| Line 112: | Line 163: | ||
== What Triggers the Event == | == What Triggers the Event == | ||
Native score | Native score adjustments include values generated by normal engine systems such as: | ||
* Damage and hit scoring. | * Damage and hit scoring. | ||
| Line 121: | Line 172: | ||
* Clear, life, and rush bonuses awarded during stage completion. | * Clear, life, and rush bonuses awarded during stage completion. | ||
The precise | The precise adjustment depends on the applicable model, attack, level, and project configuration. Each native adjustment runs the numbered script for the affected player when present, followed by <code>scoreall.c</code> when present. Negative model or level score values can turn applicable defeats, pickups, obstacles, or exits into score penalties. | ||
Several operations can change a player's stored total without representing a new score | Several operations can change a player's stored total without representing a new score adjustment. Direct score-property writes, loading saved data, and internal score resets do not pass through the native score routine and therefore do not execute numbered score scripts or <code>scoreall.c</code>. This separation prevents initialization, restoration, or scripted replacement of a total from being mistaken for gameplay scoring. | ||
== Example: | == Example: Reward and Penalty Feedback == | ||
The following <code>data/scripts/score1.c</code> records Player 1's latest | The following <code>data/scripts/score1.c</code> records Player 1's latest adjustment and selects separate feedback for rewards and penalties. An update, draw, or HUD script can consume the stored values and provide the desired presentation. | ||
<syntaxhighlight lang="c" line> | <syntaxhighlight lang="c" line> | ||
void main() | void main() | ||
{ | { | ||
long adjustment = getlocalvar("score"); | |||
if ( | if (adjustment != 0) | ||
{ | { | ||
setglobalvar(" | setglobalvar("p1_last_score_adjustment", adjustment); | ||
if ( | if (adjustment >= 1000) | ||
{ | { | ||
setglobalvar("p1_score_flash", 2); | setglobalvar("p1_score_flash", 2); | ||
} | |||
else if (adjustment > 0) | |||
{ | |||
setglobalvar("p1_score_flash", 1); | |||
} | } | ||
else | else | ||
{ | { | ||
setglobalvar("p1_score_flash", 1); | setglobalvar("p1_score_flash", -1); | ||
} | } | ||
} | } | ||
| Line 150: | Line 205: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The same pattern can be used in the other numbered files. The filename supplies the player identity. Keeping visual or timed behavior in an update or draw script allows the score event to remain focused on recording the | The same pattern can be used in the other numbered files. The filename supplies the player identity. Keeping visual or timed behavior in an update or draw script allows the score event to remain focused on recording the adjustment and starting the response. | ||
== Example: Shared Team Score == | == Example: Shared Team Score == | ||
<code>scoreall.c</code> is especially useful for common systems. This compact example applies every player's rewards and penalties to a shared team tally. It assumes <code>team_score</code> was initialized to <code>0</code> by a level-start or other setup script. | |||
<syntaxhighlight lang="c" line> | <syntaxhighlight lang="c" line> | ||
void main() | void main() | ||
{ | { | ||
int player = getlocalvar("player"); | |||
long adjustment = getlocalvar("score"); | |||
long team_score = getglobalvar("team_score"); | |||
if ( | if (adjustment != 0) | ||
{ | { | ||
setglobalvar("team_score", team_score + | setglobalvar("team_score", team_score + adjustment); | ||
setglobalvar("team_score_last_player", player); | |||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The shared handler creates a cooperative tally without replacing any player's native score. The same arrangement can power team milestones, shared resources, competitive comparisons, or multiplayer challenge rules. | |||
== Other Uses == | == Other Uses == | ||
| Line 175: | Line 232: | ||
Quick applications include: | Quick applications include: | ||
* '''Presentation''' - Select sounds, flashes, text, particles, or camera effects according to the | * '''Presentation''' - Select sounds, flashes, text, particles, or camera effects according to the adjustment's sign and size. | ||
* '''Milestones''' - Detect score thresholds and trigger ranks, unlocks, achievements, or rewards. | * '''Milestones''' - Detect score thresholds and trigger ranks, unlocks, achievements, or rewards. | ||
* '''Secondary resources''' - Convert native | * '''Penalties''' - React to point loss from dangerous items, protected targets, mistakes, or other negative-score interactions. | ||
* '''Cooperative systems''' - Combine | * '''Secondary resources''' - Convert native score changes into meter, currency, experience, continues, or another custom value. | ||
* '''Cooperative systems''' - Combine adjustments from several player slots into a shared objective or team score. | |||
* '''Common handling''' - Use <code>scoreall.c</code> for project-wide scoring logic without maintaining four copies of the same script. | |||
* '''Competitive systems''' - Track momentum, compare recent gains, or announce changes in player standing. | * '''Competitive systems''' - Track momentum, compare recent gains, or announce changes in player standing. | ||
* '''Challenge logic''' - Count qualifying | * '''Challenge logic''' - Count qualifying changes, enforce score goals, or record progress for bonus conditions. | ||
* '''Statistics''' - Record | * '''Statistics''' - Record adjustment frequency, largest gains or losses, stage totals, or player-specific performance data. | ||
The numbered | The numbered filename identifies the player for <code>score#.c</code>, while local variable <code>player</code> identifies the player for <code>scoreall.c</code>. Local variable <code>score</code> provides the signed adjustment, but neither form supplies a dedicated source identifier. Systems that need to distinguish hits, defeats, pickups, bonuses, or penalties can combine the event with state recorded by the relevant attack, model, item, spawn, or level scripts. | ||
== See Also == | == See Also == | ||
| Line 191: | Line 250: | ||
* [[Model Commands#score|Model score]] | * [[Model Commands#score|Model score]] | ||
* [[Level Commands#score|Level score]] | * [[Level Commands#score|Level score]] | ||
* [[Keyscript|Key scripts]] | |||
* [[Script Overview]] | * [[Script Overview]] | ||
Latest revision as of 17:55, 20 August 2026
Score scripts are automatic event hooks that execute whenever OpenBOR processes a score adjustment through its native score routine. Two forms are available: numbered scripts for individual player slots and scoreall.c for shared project-wide handling.
Numbered scripts correspond to individual players:
data/scripts/score1.cdata/scripts/score2.cdata/scripts/score3.cdata/scripts/score4.c
The shared script receives adjustments for every player:
data/scripts/scoreall.c
Each script receives the signed 64-bit adjustment submitted to the score routine. Positive values add points, while negative values deduct them. This makes score scripts useful for custom feedback, milestones, achievements, penalties, secondary reward systems, cooperative scoring, statistics, and any other mechanic that should react immediately to native score changes.
OpenBOR's accumulated player score supports values from 0 through 18446744073709551615. This provides enough range for extreme scoring systems, large multipliers, dense projectile bonuses, and other designs without requiring creators to split a score into manually carried pieces.
Score scripts are adjustment events rather than general observers of the score property. Writing a player's score directly through script does not execute them.
Usage
Create the desired score-script files in data/scripts. OpenBOR loads them automatically, so no model, level, or project command is required.
score#.c is documentation shorthand in which # represents the player number. The literal filenames use 1 through 4.
| File | Scope | Player identification |
|---|---|---|
data/scripts/score1.c
|
Player 1 | Filename - index 0
|
data/scripts/score2.c
|
Player 2 | Filename - index 1
|
data/scripts/score3.c
|
Player 3 | Filename - index 2
|
data/scripts/score4.c
|
Player 4 | Filename - index 3
|
data/scripts/scoreall.c
|
Every player | Local variable player
|
Numbered Score Scripts
The numbered scripts receive the score adjustment. Their filename identifies the player slot.
void main()
{
long score = getlocalvar("score");
// React to the score adjustment here.
}
OpenBOR does not supply player or self automatically to a numbered score script.
Scoreall
data/scripts/scoreall.c is a shared listener for every player slot. It receives the zero-based player index in addition to the score adjustment.
void main()
{
int player = getlocalvar("player");
long score = getlocalvar("score");
// React to any player's score adjustment here.
}
scoreall.c allows common project-wide behavior can be written once instead of duplicated across four files.
No self variable is supplied because the event belongs to a player slot rather than an entity.
Execution
The immediate score-adjustment sequence is:
- OpenBOR receives a player slot and a signed amount to apply.
- OpenBOR calculates applicable extra-life thresholds.
- Positive amounts add to the player's score and saturate at
18446744073709551615. Negative amounts deduct from the score and saturate at0. - Applicable extra lives are awarded.
- OpenBOR stores the updated score total.
- The corresponding numbered score script executes with local variable
score, when present. scoreall.cexecutes with local variablesplayerandscore, when present.
The player's updated score and any extra lives from the adjustment are already available when either script executes. Native processing for that individual score adjustment is otherwise complete. Negative adjustments do not remove lives that were already awarded.
The numbered script always executes before scoreall.c. Changes made by the numbered script are therefore visible to the shared script later in the same event sequence. scoreall.c does not depend on the numbered file being present and still executes when no corresponding score#.c exists.
Score scripts execute once for each call to the native score routine, not once per update and not once for an accumulated group of adjustments. Stage-completion counting may therefore produce a sequence of small events as bonuses are transferred into the player's total.
OpenBOR may also submit an amount of zero to the score routine. Scripts can test whether score is positive, negative, or zero before producing the applicable response.
Event Data
| Variable | Type | Available in | Description |
|---|---|---|---|
score
|
Signed 64-bit integer (VT_INTEGER64)
|
Numbered scripts and scoreall.c
|
Adjustment submitted to the native score routine. Positive values add points, and negative values deduct points. |
player
|
Integer (VT_INTEGER)
|
scoreall.c only
|
Zero-based index of the player receiving the score adjustment. |
score is the requested adjustment, not the player's new total. It is also not necessarily the actual change in the stored total. An addition that reaches the unsigned maximum or a deduction that reaches zero still supplies its original signed amount to the event.
Changing the local score variable does not alter the adjustment or the stored player score because the event executes after native score processing. The event supplies the adjustment rather than the running total. Systems may accumulate the signed 64-bit changes in a global variable to build an independent tally, as shown below.
Score Range
OpenBOR separates the signed values used to adjust score from the unsigned value used to store the player's total.
| Value | Type | Minimum | Maximum |
|---|---|---|---|
| Player score total | Unsigned 64-bit integer | 0
|
18446744073709551615
|
| Model and level score value | Signed 64-bit integer | -9223372036854775808
|
9223372036854775807
|
| Score-script event value | Signed 64-bit integer (VT_INTEGER64)
|
-9223372036854775808
|
9223372036854775807
|
The player's maximum total is also known as UINT64_MAX, or 264 - 1. Score adjustment uses saturation at both ends. Positive adjustments that would exceed the maximum store UINT64_MAX, while negative adjustments that would pass below zero store 0.
Player totals, saved scores, and high-score entries preserve the unsigned 64-bit range. Model and level score commands accept signed 64-bit values, allowing creators to assign either rewards or penalties without replacing the native score system.
The scoreformat setting continues to pad short values to nine digits. Nine digits are a minimum display width rather than a limit, so larger totals remain visible in full.
What Triggers the Event
Native score adjustments include values generated by normal engine systems such as:
- Damage and hit scoring.
- Defeating entities with a configured score value.
- Collecting items with a configured score value.
- Damaging obstacles.
- Reaching an end-level entity with a score value.
- Clear, life, and rush bonuses awarded during stage completion.
The precise adjustment depends on the applicable model, attack, level, and project configuration. Each native adjustment runs the numbered script for the affected player when present, followed by scoreall.c when present. Negative model or level score values can turn applicable defeats, pickups, obstacles, or exits into score penalties.
Several operations can change a player's stored total without representing a new score adjustment. Direct score-property writes, loading saved data, and internal score resets do not pass through the native score routine and therefore do not execute numbered score scripts or scoreall.c. This separation prevents initialization, restoration, or scripted replacement of a total from being mistaken for gameplay scoring.
Example: Reward and Penalty Feedback
The following data/scripts/score1.c records Player 1's latest adjustment and selects separate feedback for rewards and penalties. An update, draw, or HUD script can consume the stored values and provide the desired presentation.
void main()
{
long adjustment = getlocalvar("score");
if (adjustment != 0)
{
setglobalvar("p1_last_score_adjustment", adjustment);
if (adjustment >= 1000)
{
setglobalvar("p1_score_flash", 2);
}
else if (adjustment > 0)
{
setglobalvar("p1_score_flash", 1);
}
else
{
setglobalvar("p1_score_flash", -1);
}
}
}
The same pattern can be used in the other numbered files. The filename supplies the player identity. Keeping visual or timed behavior in an update or draw script allows the score event to remain focused on recording the adjustment and starting the response.
Example: Shared Team Score
scoreall.c is especially useful for common systems. This compact example applies every player's rewards and penalties to a shared team tally. It assumes team_score was initialized to 0 by a level-start or other setup script.
void main()
{
int player = getlocalvar("player");
long adjustment = getlocalvar("score");
long team_score = getglobalvar("team_score");
if (adjustment != 0)
{
setglobalvar("team_score", team_score + adjustment);
setglobalvar("team_score_last_player", player);
}
}
The shared handler creates a cooperative tally without replacing any player's native score. The same arrangement can power team milestones, shared resources, competitive comparisons, or multiplayer challenge rules.
Other Uses
Quick applications include:
- Presentation - Select sounds, flashes, text, particles, or camera effects according to the adjustment's sign and size.
- Milestones - Detect score thresholds and trigger ranks, unlocks, achievements, or rewards.
- Penalties - React to point loss from dangerous items, protected targets, mistakes, or other negative-score interactions.
- Secondary resources - Convert native score changes into meter, currency, experience, continues, or another custom value.
- Cooperative systems - Combine adjustments from several player slots into a shared objective or team score.
- Common handling - Use
scoreall.cfor project-wide scoring logic without maintaining four copies of the same script. - Competitive systems - Track momentum, compare recent gains, or announce changes in player standing.
- Challenge logic - Count qualifying changes, enforce score goals, or record progress for bonus conditions.
- Statistics - Record adjustment frequency, largest gains or losses, stage totals, or player-specific performance data.
The numbered filename identifies the player for score#.c, while local variable player identifies the player for scoreall.c. Local variable score provides the signed adjustment, but neither form supplies a dedicated source identifier. Systems that need to distinguish hits, defeats, pickups, bonuses, or penalties can combine the event with state recorded by the relevant attack, model, item, spawn, or level scripts.