Home   Archive   Permalink



Field text to block

I have updated some field text and I want to save it to a block, which has already been defined (I want to overwrite it). The field consists of words and some of them must have quotes around them. I tried this
    
name: to-block f5/text
    
but the problem is when I add a word into the f5 field by typing it in, then update the block using a drop down list to change another word, the original value for "name" is used, not the new value, with the added word. Tips??
    


posted by:   Tony     11-Jan-2012/9:59:57-8:00



Here is the full script --
    
settings: [--crf 20 --preset faster]
gui: layout [
     across
label "Select crf:" crf1: drop-down 100 data [20 18 19 21 25] [set-face f5 mold/only replace settings select settings '--crf value settings: to-block f5/text]
]
view center-face gui
    
See the "settings: to-block f5/text" line. I want that to overwrite the settings variable with what current is in f5/text. The way I have it here doesn't work.

posted by:   tony     11-Jan-2012/12:12:53-8:00



It looks it works:
settings: [--crf 20 --preset faster]
gui: layout [
     across
f5: field 100
label "Select crf:" crf1: drop-down 100 data [20 18 19 21 25] [set-face f5 mold/only replace settings select settings '--crf value probe name: to-block f5/text]
box 10x100 ;just to make the window bigger
]
view center-face gui
;when I select a value from the list it probes:
>> [--crf 18 --preset faster]
>> [--crf 20 --preset faster]
    
You said in your first post:
name: to-block f5/text
    
But in the second one it is:
settings: to-block f5/text
    
And there is no F5 in the full script, so I confused.


posted by:   Endo     12-Jan-2012/3:59:05-8:00



OK, sorry, here is the full script with proper variables
    
R E B O L [Title: "test"]
x264comline: [--crf 20 --preset faster --tune film]
    
gui: layout [
size 900x500
     across
label "Select crf:" crf1: drop-down 100 data [20 18 19 21 25] [set-face f5 mold/only replace x264comline select x264comline '--crf value probe x264comline: to-block f5/text]
return
label "x264 Command Line:" tab f5: field 600 mold/only x264comline return
]
view center-face gui
    
Try it. When I select a new crf from the drop down the console screen opens with the proper new values but they are not returned to the f5 field.

posted by:   tony     12-Jan-2012/11:10:54-8:00



I see the correct value on the console window and on F5 field.
F5 field text changed to the value I selected from the drop list.
I cannot see the problem.
    
Here I added a "probe F5/text" it gives the same value as in settings:
    
R E B O L [Title: "test"]
x264comline: [--crf 20 --preset faster --tune film]
        
gui: layout [
size 900x500
     across
label "Select crf:" crf1: drop-down 100 data [20 18 19 21 25] [set-face f5 mold/only replace x264comline select x264comline '--crf value probe x264comline: to-block f5/text probe f5/text]
return
label "x264 Command Line:" tab f5: field 600 mold/only x264comline return
]
view center-face gui


posted by:   Endo     12-Jan-2012/11:46:06-8:00



Don't you get a console window opening showing this -
    
[--crf 18 --preset faster --tune film]
"--crf 18 --preset faster --tune film"

posted by:   tony     12-Jan-2012/12:23:13-8:00



Ok, I understand now, Probe allows us to see what we're doing. I removed "Probe" and the console window does not show, good. It works but just one thing it must do is if I manually type in another word in the f5 field, then select a new drop down I want that new word also to appear in the f5 field. As of now, any word like "--level" that is added to the f5 field is erased when you select a new drop down number.

posted by:   Tony     12-Jan-2012/12:31:44-8:00



Yes "Probe" is like Print, it writes any value (except unset!) to Console window mainly for debugging purposes.
It is useful because it "returns" the value that it wrote.
try these examples on Console window:
    
>> probe 3 * 5
15
== 15
>> 3 * probe 5
5
== 15
    
>> x: 5 reduce [x]
== [5]
>> x: 5 reduce probe [x]
[x]
== [5]
>> x: 5 probe reduce probe [x]
[x] ;first probe (on the right side)
[5] ;second probe (on the left side)
== [5]
>> probe x: 5 probe reduce probe [x]
5    ;first probe left most
[x] ;second probe, right most
[5] ;third probe, in the middle
== [5] ;probe returns the last value
    


posted by:   Endo     13-Jan-2012/8:35:33-8:00



For your second question, "overwritting the F5 text":
    
it is because, if you SET a new value to a variable (word) it always overwrites the older value.
    
If you don't want this, you should CHANGE the value instead of SETting it.
    
Here is what I mean, try it on Console:
    
>> x: "test" ;think that this is F5/text
>> y: x
>> print [x y]
test test ;x and y "points" to same value (same string, same memory position)
    
>> x: "hello"
== "hello"
>> print [x y]
hello test
    
x changed, but y does not. we created a new value and SET x to it. So x and y have totally different values now.
    
Here is the second example:
>> x: "test" ;think that this is F5/text
>> y: x
>> print [x y]
test test ;ok
    
>> clear x
>> print [x y]
     ;they both cleared
>> append x "hello"
>> print [x y]
hello hello
    
Here we did not re-set the value of x, we just changed it. we did not overwrite.
    
I advice you to practice on Series Values (read about them on Core.pdf) and Series functions like CHANGE, APPEND, INSERT, FIND, CLEAR etc.
    
I hope this will give you the idea about your problem.
    
set-face function sets (creates) a new value, does not change the original one.


posted by:   Endo     13-Jan-2012/8:49:34-8:00



Thanks Endo. In my case I do want a new value to go into the variable "x264comline" and that's what I thought that "x264comline: to-block f5/text]" would do. How come it doesn't? This command is supposed to look at what's in f5/text and save it as variable x264comline including what else I have typed in the f5 field manually but it doesn't. What am I missing?

posted by:   tony     13-Jan-2012/9:57:47-8:00



First, you type something into the field (f5), f5/text holds what you've typed.
But then, when you click on drop-list you set f5/text to something else.
Look,
set-face f5 mold/only replace x264comline select x264comline '--crf value
this line changes the f5/text, so you lost what you've manually typed.
    
here is your code:
     across
     label "Select crf:" crf1: drop-down 100 data [20 18 19 21 25] [set-face f5 mold/only replace x264comline select x264comline '--crf value x264comline: to-block f5/text f5/text]
     return
    
chage it to:
     across
     label "Select crf:" crf1: drop-down 100 data [20 18 19 21 25] [set-face f5 mold/only replace x264comline select x264comline '--crf value x264comline: to-block f5/text f5/text]
     btn "Show" [probe f5/text]
     return
    
then type something on f5 field, and press the button (don't select anything from drop-list)
now you'll see the text that you manually typed.
    
But there is one more thing that you should think about it:
if you write something that is cannot convertable to a block, you get an error on "to-block f5/text"
    
try typing this on the field: 3*
this cannot be convertable to a block because it is not a correct REBOL value.
    
>> to-block "3*"
** Syntax Error: Invalid integer -- 3*
    
so you need to check if there is an error:
x: either error? try [t: to-block f5/text] [copy "error!"] [t]


posted by:   Endo     14-Jan-2012/16:28:16-8:00



Well, I just figured it out! I just put --
    
x264comline2: to-block f5/text f5/text: mold/only x264comline2
    
in the front of the action as shown above and it saves whatever I have typed to a new variable then updates that with the new dropdown value. Done!

posted by:   tony     15-Jan-2012/0:24:09-8:00