[Closed] return a text with a popup window
That is a bit stupid but I don’t know how to open a window that returns to me a text.
I call my function and a floating window appears. I enter the text and I press ENTER. The function closes the window and returns the text.
the call of function would be something like this:
fn queryString text = (???)
theString=queryString “enter your name”
From what I understand you should use a rollout with an edittext box and pull the value from it.
Look in Maxreference for EditText.
I would like that it works when I have already a floating window open.
I have a main program and with this program I open this window with a fn() call …
I would wish that the memory be released too.
I hope I made my problem clearer.
You will have to script your own modal dialog for this.
(
local test
rollout enterText "Enter Text"
(
edittext theText
on theText entered txt do
(
test.theEnteredText.text = txt
destroyDialog enterText
)
)
rollout test "Test"
(
button pressme "Press me to enter text!"
label theEnteredText "Nothing entered yet..."
on pressme pressed do
createDialog enterText modal:true
)
createDialog test
)
This works ok, the only problem is that “resp” is defined globally here…for some reason if I defined resp locally inside the function the rollout couldn’t see it
resp
function queryText str title=
(
rollout textGetter title
(
edittext txt caption:str
button bOk name:"Ok"
on bOk pressed do
(
resp = txt.text
destroyDialog textGetter
)
)
createDialog textGetter
return resp
)
resp = queryText "what's your name?" "name box"
edit: shucks, bobo beat me to it
Oh thanks Bobo and Sthu ! ( and more especially bobo because its program works lolll I joke )
Thanks again !
Haha, mine DOES work! And it follows the function specs you gave unlike bobo’s!
Ok ok “does work”
… or … could do work ?
with some (little) modifications
(
local resp
function queryText title =
(
rollout textGetter title
(
edittext txt "what's your name?"
button bOk "Ok"
on bOk pressed do
(
resp = txt.text
destroyDialog textGetter
)
)
createDialog textGetter modal:true
return resp
)
resp = queryText "name box"
messageBox ("resp="+resp as string)
)
In fact I don’t understand why but the ‘caption’ part of the edittext does not work with a variable like ‘caption:str’. So I replaced it directly in the function by “what’s your name?”
A button does not have a property ‘name’.
If I add ( ) around the script It’s possible to use a local variable for resp.
And ‘modal:true’ allows that the program awaits the answer of queryText. Else it does not await the answer.
have a good day
If I add ( ) around the script It’s possible to use a local variable for resp.
interesting, but it should only be local inside the function and this is still outside it
No, it should be local to the main script scope, because you want to use it as a “private global” in any part of the script without polluting the global scope…
This is because the local variable of the function is destroyed the moment the function finishes executing, while the “life expectancy” of a rollout is unlimited (as it has to keep all its controls and local variables). Once you define a rollout, it stays in memory and can be added/removed/dialogized at any time…
This is why MAXScript does not allow you to use a function’s local variable inside the rollout, as the rollout will live in the same scope as the function, not in the function’s scope.