PDA

View Full Version : return a text with a popup window


prettyPixel
10-06-2005, 09:47 PM
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"

antonv
10-06-2005, 10:25 PM
From what I understand you should use a rollout with an edittext box and pull the value from it.
Look in Maxreference for EditText.

prettyPixel
10-06-2005, 10:52 PM
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.

Bobo
10-06-2005, 11:00 PM
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
)

stuh505
10-06-2005, 11:06 PM
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 :P

prettyPixel
10-07-2005, 12:02 AM
Oh thanks Bobo and Sthu ! ( and more especially bobo because its program works lolll I joke ;) )

Thanks again !

stuh505
10-07-2005, 01:43 AM
Haha, mine DOES work! And it follows the function specs you gave unlike bobo's! :(

prettyPixel
10-07-2005, 03:11 AM
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

stuh505
10-07-2005, 05:28 AM
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

Bobo
10-07-2005, 05:54 AM
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.

stuh505
10-07-2005, 03:16 PM
Ah...I see:)

CGTalk Moderation
10-07-2005, 03:16 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.