Appearance
self
The self
refers to the script itself.
Pinokio scripts automatically re-construct themselves every time an instruction is executed, using the following algorithm:
- Every time an instruction in a
run
array is about to be executed, the following algorithm is run. - First reload the currently executing script file. (if the current script is
index.json
, Pinokio automatically reloads the file to put the up-to-date JSON object in memory) - Auto-import all JSON and JavaScript modules in the same folder (as well as subfolders) using the import algorithm
- The instruction (often contains template expressions) is filled out with the resulting memory
- The instantiated instruction is executed.
Here's an example script:
json
{
"run": [{
"method": "set"
"params": {
"self": {
"config.json": {
"apikey": "blablablabll",
"apisecret": "secretsecretsecret"
}
}
}
}, {
"method": "log",
"params": {
"json": "{{self.config}}"
}
}]
}
- When the first instruction is run, it sets the
self.config.apikey
andself.config.apisecret
values through the set API. - The next instruction prints the
self.config
, and this will be based on the most up-to-date memory state, therefore will print the following:
json
{ "apikey": "blablablabll", "apisecret": "secretsecretsecret" }