A second answer window?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
A second answer window?
How's it going forum? I'm having a bit of trouble with the 'answer' prompt, and I'd like to know if anybody would be able to help me, regardless of whether or not this is the place to ask. (Personally, I think it is, seeing as I'm completely new to live code)
Anyway, for my first assignment in school, I decided to use the code of the Shakespeare insult machine to develop a name generator of sorts.
The coding is sound, the dictionary for the first and last name is packed, and I can successfully run the prompt by clicking a button, so I'm rather proud of how it works so far.
I do have a slight problem, however. After I click the button, which runs the card script, I get the answer window I'm looking for, complete with the randomized name I was looking for. But after closing that window, a second answer window opens up, this one totally blank, save for a button. It's not a huge issue, but it's kind of annoying and I'm unsure why it keeps appearing.
So what I guess I'm asking is "Why is this second window showing up, and how do I fix it?"
I'm running on a deadline, and I'd like to solve this as soon as possible, but I'm happy to help clarify the situation with images later on, if necessary.
Thanks so much in advance!
Anyway, for my first assignment in school, I decided to use the code of the Shakespeare insult machine to develop a name generator of sorts.
The coding is sound, the dictionary for the first and last name is packed, and I can successfully run the prompt by clicking a button, so I'm rather proud of how it works so far.
I do have a slight problem, however. After I click the button, which runs the card script, I get the answer window I'm looking for, complete with the randomized name I was looking for. But after closing that window, a second answer window opens up, this one totally blank, save for a button. It's not a huge issue, but it's kind of annoying and I'm unsure why it keeps appearing.
So what I guess I'm asking is "Why is this second window showing up, and how do I fix it?"
I'm running on a deadline, and I'd like to solve this as soon as possible, but I'm happy to help clarify the situation with images later on, if necessary.
Thanks so much in advance!

Re: A second answer window?
Hi.
Another "answer" command was written somewhere. Can you find it? Can you step through the handlers until that second one appears? Otherwise, you need to post your scripts.
Craig Newman
Another "answer" command was written somewhere. Can you find it? Can you step through the handlers until that second one appears? Otherwise, you need to post your scripts.
Craig Newman
Re: A second answer window?
As far as I can tell, there is only one "answer" command, and it's situated on a card script, just like the "Shakespeareinsult()"dunbarx wrote:Hi.
Another "answer" command was written somewhere. Can you find it? Can you step through the handlers until that second one appears? Otherwise, you need to post your scripts.
Craig Newman
I can post the code here, if it helps.
This is the card script:
function ponynamer
answer "Hi! My name is" \
&& any word of field "one"\
&& any word of field "two" & "!"
end ponynamer
And this is the code for the button
on mouseUp
answer ponynamer()
end mouseUp
(PS, yes, this code is for naming ponies. I doubt that's the problem, though


Re: A second answer window?
Hi Tommy.
1. welcome to the forum!
2. Looking at your script, this (2 dialogs) is correct behavior!
This is a FUNCTION, yet does not RETURN anything, BUT this will display the FIRST ANSWER dialog!
This will ANSWER (the second ANSWER dialog!) the non-existing RESULT of the above mentioned function and that is EMPTY
To solve this problem do this:
1. Make "ponynamer" a handler:
Then simply call that handler
Best
Klaus
1. welcome to the forum!

2. Looking at your script, this (2 dialogs) is correct behavior!

This is a FUNCTION, yet does not RETURN anything, BUT this will display the FIRST ANSWER dialog!
Code: Select all
function ponynamer
answer "Hi! My name is" && any word of field "one" && any word of field "two" & "!"
end ponynamer

Code: Select all
on mouseUp
answer ponynamer()
end mouseUp
1. Make "ponynamer" a handler:
Code: Select all
COMMAND ponynamer
answer "Hi! My name is" && any word of field "one" && any word of field "two" & "!"
end ponynamer
Code: Select all
on mouseUp
ponynamer
end mouseUp
Klaus
Re: A second answer window?
Hi.
Couple of things.
NEVER name a field with a reserved word. Like "1" or "one". Trust me. OR rather, keep doing so, and you will learn a great deal about how LC parses object references.
Sorry to be so abrupt. Tough love.
You are calling a function, but using that function as a command handler. Functions should be used to return a value, using the "return" command.
Try this:
Couple of more things. Though there is nothing wrong with doing so, why call a separate handler at all? Can you rewrite your original handlers to actually use a function call correctly? This would be a good exercise.
Craig Newman
Couple of things.
NEVER name a field with a reserved word. Like "1" or "one". Trust me. OR rather, keep doing so, and you will learn a great deal about how LC parses object references.
Sorry to be so abrupt. Tough love.
You are calling a function, but using that function as a command handler. Functions should be used to return a value, using the "return" command.
Try this:
Code: Select all
on mouseUp
ponynamer
end mouseUp
on ponynamer
answer "Hi! My name is" \
&& any word of field "one"\
&& any word of field "two" & "!"
end ponynamer
Craig Newman
Re: A second answer window?
Thanks for the advice (and I understand why I shouldn't name it something as obscure as "one". Going to change it to something else) The second solution did, in fact, work, and the program runs fine now.dunbarx wrote:Hi.
Couple of things.
NEVER name a field with a reserved word. Like "1" or "one". Trust me. OR rather, keep doing so, and you will learn a great deal about how LC parses object references.
Sorry to be so abrupt. Tough love.
You are calling a function, but using that function as a command handler. Functions should be used to return a value, using the "return" command.
Try this:Couple of more things. Though there is nothing wrong with doing so, why call a separate handler at all? Can you rewrite your original handlers to actually use a function call correctly? This would be a good exercise.Code: Select all
on mouseUp ponynamer end mouseUp on ponynamer answer "Hi! My name is" \ && any word of field "one"\ && any word of field "two" & "!" end ponynamer
Craig Newman
I don't completely understand what you mean by calling a separate handler, seeing as my knowledge of code goes about as far as basic html code, meaning that this project is totally new territory to me.
So correct me if I'm wrong, but what you're asking of me is that I write the command on the card script into the button's handler?
If so, then my command would look like this, right?
Code: Select all
on mouseUp
answer "Hi! My name is" \
&& any word of field "one"\
&& any word of field "two" & "!"
end mouseUp

Re: A second answer window?
Hi Tommy,
"Outsourcing" handlers makes sense if you need to call it from more that one specific object,
like if you would need more than one button on the card that "names the pony".
In that case you would place the "ponynamer" handler into the card script and can
have multiple buttons or other object with the script:
You get the picture
Best
Klaus
Yesif so, then my command would look like this, right?Code: Select all
on mouseUp answer "Hi! My name is" \ && any word of field "one"\ && any word of field "two" & "!" end mouseUp

"Outsourcing" handlers makes sense if you need to call it from more that one specific object,
like if you would need more than one button on the card that "names the pony".
In that case you would place the "ponynamer" handler into the card script and can
have multiple buttons or other object with the script:
Code: Select all
on mouseup
ponynamer
end mouseup

Best
Klaus
Re: A second answer window?
Tom.
Another reason to place a section of code in another handler is to condense your main line. I suggested that you did not need it in this case because the whole handler was only a few lines, and separating it into two actually increases the total. There are times when you might have several pages of handlers in a single script. If you can pack, say a well-defined section somewhere else, say the stack script, or even just to the bottom of the working script, it might make for easier reading:
Craig
Another reason to place a section of code in another handler is to condense your main line. I suggested that you did not need it in this case because the whole handler was only a few lines, and separating it into two actually increases the total. There are times when you might have several pages of handlers in a single script. If you can pack, say a well-defined section somewhere else, say the stack script, or even just to the bottom of the working script, it might make for easier reading:
Code: Select all
on mouseUp
answer "Hi! My name is" \
&& any word of field "one"\
&& any word of field "two" & "!"
put someLongAndTediousCalculation(existence) into lifeTheUniverseAndEverything
answer lifeTheUniverseAndEverything
end mouseUp
function someLongAndTediousCalculation var
doLotsOfStuff
return 42
end someLongAndTediousCalculation
Re: A second answer window?
Okay, thanks a bunch guys! I finished the code, and I'm pretty impressed with the results.
Thanks so much for the help, it really means a lot to me.
If you ever feel like creating a [ponysona, I'll gladly use it to generate a name or two for ya!
Thanks so much for the help, it really means a lot to me.
If you ever feel like creating a [ponysona, I'll gladly use it to generate a name or two for ya!

