set-state!

state

state-atom

set-state!

Arguments
[& state-vals]
Docstring
Set sketch-specific state. May only be called once (ideally in the
setup fn).  Subsequent calls have no effect.

Example:
(set-state! :foo 1 :bar (atom true) :baz (/ (width) 2))
Works only inside sketch functions?
Yes
Original Processing method
None. It is present only in Quil.

state

Arguments
[][key]
Docstring
Retrieve sketch-specific state by key. Must initially call
set-state! to store state. If no parameter passed whole
state map is returned.

(set-state! :foo 1)
(state :foo) ;=> 1
(state) ;=> {:foo 1}
Works only inside sketch functions?
Yes
Original Processing method
None. It is present only in Quil.

state-atom

Arguments
[]
Docstring
Retrieve sketch-specific state-atom. All changes to the
atom will be reflected in the state.

(set-state! :foo 1)
(state :foo) ;=> 1
(swap! (state-atom) update-in [:foo] inc)
(state :foo) ;=> 2
Works only inside sketch functions?
Yes
Original Processing method
None. It is present only in Quil.