I want to set a variable in a Rebol 3 button handler (GUI) and use the value after the window is closed. How do I get the value outside of the view block? Here is an example code:
view [
v_username: field
button "Submit" on-action [
username: get-face v_username
close-window face
]
]
probe username
The result is "" regardless of the content of v_username.
Does it have to be 'declared' as a global variable? Should I get this value from a returned value of the view?
The 'on-action
block when invoked is wrapped in a function
(Rebol function where set-words are assumed local to the function). You have a couple of options to work around this:
Use an object to store the values in (set-paths are not bound within function
):
values: context [username: none]
view [... on-action [values/username: get-face ...]]
Use 'set
to set the word. I find this a little less reliable as it's uncertain the context of the word you are setting:
view [... on-action [set 'username get-face ...]]
Though perhaps the best option is to keep in mind that the words you assign to styles are bound the context you're working in, so:
view [username-field: field ...]
username: get-face username-field