view [
style small: area 30x30
button button button return
button button button return
area below small small small
]
<center>
parameter ( (optional) center of rotation (pair!)) doesn't matter. We should calculate <center>
parameter other way.
draw
/shape
of the Logo's features (rotation/heading, loops, conditions, functions etc)?
Draw
is static while watching the turtle move and draw is a big part of that experience, which means your Logo drawing commands are really tied to a timer of some kind. What we could do, then, is set a canvas face for the turtle commands, and as you run them, the draw
block for that face would be updated, so the Logo part is in control there.
while
that checks a condition every time (before entering body
block) and you have if
that need to check it once. You need a block to run code multiple times so if
doesn't need it.; Hi, newby question about contexts. I want to be able to set values in the do-block of a button, but I'm
; got "word not bound to context" error:
f: function [] [
return view/no-wait [
button "test" [
x: "hello"
]
]
]
; -> error: word not bound to context
; I tried two workarounds, setting the values in an options block passed to face,
; and setting the values in a context, but I'd like to know if there is a way
; to carry out my original intentions using bind or something. I believe the
; error is something to do with anonymous functions in the dialect not
; having a context?
; Set data in face options
f: function [] [
return view/no-wait/options [
button "test" [print face/parent/data/x]
] [data: [x: 100]]
]
; set data in created context
f: function [] [
return context [
x: "hello"
init: view/no-wait [
button "test" [
print x
]
]
]
]
; Thanks!
function
makes all set-word
s found in function's body local by default. To have x
in global context use func
instead:>> f: func [] [ return view/no-wait [ button "test" [ x: "hello" ] ] ]
== func [][return view/no-wait [button "test" [x: "hello"]]]
>> f
== make object! [
type: 'window
;...
>> x
== "hello"
/no-wait
seems to be a culprit.f: function [] [return view [do [x: none] button "test" [x: "hello" probe x]] ]
vs g: function [] [return view/no-wait [do [x: none] button "test" [x: "hello" probe x]] ]
both has x
as local (?? g
) but only 2nd one doesn't work.
/no-wait
is not the culprit. In the first case f
calls view
and waits until it finishes, and x
has its context available because we're using it during f
call. In the second case you explicitly ask to not enter View event loop, so you instantly get face object back, which has x
in it bound to f
. Problem is that f
is gone, since function call was just finished. Hence the error message.