Skip to reading
The Variable Designer

17. Share a value with PCA Script

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

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.

Code example
language 1.0
Code example
global score = 0
Code example
function run(context)
    add 5 to score
    return true
end

What 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.

Source table from 17. Share a value with PCA Script, page 29
PCA Script choiceUse it for
globalShared game state that other actions or scripts need to read.
letTemporary 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.

Page 29 of 37Permalink
Go to page