...
Code Block |
---|
language | js |
---|
title | Example KViZ File |
---|
|
image "Lights.svg"
load "some-js-library"
load "some-other-js-library"
init
'
// javascript global variable initialization
// and function definition
// e.g. var hugo = "hugo"
'
handle showLight
in "#theRect"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.fill = status === 0 ? "red" : status === 1 ? "yellow" : "green"
'
handle showLight
in "#theRedOne"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.opacity = status === 1 || status === 2 ? 0 : 1
'
handle showLight
in "#theRedOne"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.opacity = status === 0 || status === 2 ? 0 : 1
'
handle showLight
in "#theRedOne"
with (elem, status)
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.opacity = status === 0 || status === 1 ? 0 : 1
' |
...
Code Block |
---|
language | js |
---|
title | Interaction example |
---|
|
image "Lights.svg"
handle showLight
in "#theRect"
with (elem, status, datapool) // datapool can always be added to have access to every value in the datapool
'
// elem is the element referenced via "in"
// status is the value of showLight
elem.style.fill = status === 0 ? "red" : status === 1 ? "yellow" : "green"
'
event "click"
on "#theRect"
step simulation
set showLight
'
if (showLight != 1) {
return 1 // this sets showLight to 1
}
'
// Only set this boolean variable in this tick
event "click"
on "#theRedOne"
signal thisIsABoolean |
Scripts that are not associated to a specific value
Scripts can always be associated to a value instead. However it makes clear that is the case:
Code Block |
---|
language | js |
---|
title | Script example |
---|
|
image "Lights.svg"
script (datapool)
'
// You are able to write to inputs of the model via the datapool.
datapool.onInput = true
' |