17. Share a value with PCA Script
PCA Script has its own language for shared variables. A global declaration connects to the runtime store, so the score below is the score from Variable Designer. Its initial expression is used when that global value is missing; it does not reset an existing score every time run is called.
1. Open PCA Script Designer and add a script with ID award_pca.
2. Enter the source below, validate it and apply the changes.
3. Call the script from a suitable action list, then inspect score in the gameplay preview.
language 1.0global score = 0function run(context)
add 5 to score
return true
endWhat the five-point test proves#
If score is 30 before this script runs, it should be 35 afterward. If it runs again, it should be 40. The global declaration is not an instruction to start over at zero on each call.
Use let for a temporary local value inside the script. A local calculation and a shared game value have different jobs; give them different names if that makes the code easier to follow.
| PCA Script choice | Use it for |
|---|---|
| global | Shared game state that other actions or scripts need to read. |
| let | Temporary work in the script, such as a calculation or a loop value. |
PCA Script 1.0 does not use the native GDScript Variable.score.value syntax for these designer records. Use the language’s global declaration and commands, as shown here.
The next page shows the same five-point change in Lua and BASIC. Those are alternatives, not three rewards you must chain together for one puzzle.
