I’m trying to send a text from a java function to ruby. This will be the input of a ruby function that gerenare another text.
I’m having problems because I don’t know how to send one text and return a different one to the same java function.
This will be a simplified example:
function myFunction(text1) {
sketchup.test1(test1);
alert("Received: " + suposedTextReturned)
}
This function send “text1” to ruby.
dialog.add_action_callback("test1") {|action_context, test1|
#function
suposedTextReturned = "This text was received from ruby function"
}
This callback generates “suposedTextReturned”
How can I use this text again in the java function in this line?
alert("Received: " + suposedTextReturned)
I tried with return suposedTextReturnedbut is not working
Yes, it worked!
I tried with return at the end of ruby callback but there was an error. With a string at the end there is no problem.
Thanks a lot @MSP_Greg
The Chromium HTML dialog windows use JavaScript, not Java (which is a different yet related coding language.)
FYI, the Ruby language name is capitalized.
…
Actually, not. This JavaScript function is sending the value of test1nottext1 to Ruby.
Ie, … the JS argument and the Ruby callback argument have mismatched identifier names.
Greg’s example also parroted this error.
…
return only works from methods.
But it is optional at the end of a block because (as said) the value of the last statement will be returned anyway.
A few weeks ago I wrote an HtmlDialog benchmark testing two vectors
[‘execute_script’, ‘on_completed’] and [‘DOM’, ‘DOM into DocumentFragment’, ‘innerHTML’]. All six combinations performed at about the same speed, so the choice is immaterial. That might not be the case with large and complex DOM manipulations…
Hence, I just copied some code from that, and didn’t look at the posted example or run the code…
test1 is what I needed to send but in my final code I wrote the same word in both “text1” and “test1” and It worked. I will pay more attention next time
That means that in this quoted lines “ruby_test” is doing nothing?