set-state!

state

state-atom

set-state!

Arguments
[& state-vals]
Docstring

Set sketch-specific state. May only be called once (ideally in the setup function). 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.
Original p5js method
None.
Example
; 
; setup
; 
(q/set-state! :text "I'm state!" :year (q/year))
; 
; draw
; 
(q/background 255)
(q/fill 0)
(q/text (q/state :text) 10 20)
(q/text (str "Full state: " (q/state)) 10 40)
try example

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.
Original p5js method
None.
Example
; 
; setup
; 
(q/set-state! :text "I'm state!" :year (q/year))
; 
; draw
; 
(q/background 255)
(q/fill 0)
(q/text (q/state :text) 10 20)
(q/text (str "Full state: " (q/state)) 10 40)
try example

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.
Original p5js method
None.
Example

There are no examples for this function. You can request examples which will help us to prioritize this funciton.