building an answer string programmatically
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 52
- Joined: Mon Apr 06, 2020 1:19 pm
- Location: Thailand
- Contact:
building an answer string programmatically
Hi:
I'd like to produce this code answer "how many" with "all" or "none" programmatically by building the options part as a text string. For the life of me I can't work out how to do it.
so I am looking to build a string that looks like "all" or "none", put it into x so I can write
answer "how many" with x
Is there a way to do this? My life, which is considerably like a doughnut would improve to be a veritable jam doughnut were there a solution.
Bruce
I'd like to produce this code answer "how many" with "all" or "none" programmatically by building the options part as a text string. For the life of me I can't work out how to do it.
so I am looking to build a string that looks like "all" or "none", put it into x so I can write
answer "how many" with x
Is there a way to do this? My life, which is considerably like a doughnut would improve to be a veritable jam doughnut were there a solution.
Bruce
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: building an answer string programmatically
hi Bruce,
Hi,
You may use a group instead an answer dialog.
A group with a grc rectangle with the stack rect blendlevel 100.
This group must have a script to trap mouseevents.
best regards
Jean-Marc
Hi,
You may use a group instead an answer dialog.
A group with a grc rectangle with the stack rect blendlevel 100.
This group must have a script to trap mouseevents.
best regards
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Hmmm.
Welcome to LC and the forum.
Do you mean something like this:
Craig
Welcome to LC and the forum.
Do you mean something like this:
Code: Select all
on mouseUp
put "All" into firstChoice
put "None" into secondChoice
answer "How many" with firstChoice or secondChoice
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Jean-Marc.
Either you or I are off in the weeds. Let me check my immediate surroundings. Hmmm. Leafy.
Craig
Either you or I are off in the weeds. Let me check my immediate surroundings. Hmmm. Leafy.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Bruce.
Or did you mean something like:
which looks like it ought to work, but does not. But before I start fiddling with this, is that what you meant?
Craig
Or did you mean something like:
Code: Select all
on mouseUp
put "All or None" into temp
do "answer with" && temp
end mouseUp
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: building an answer string programmatically
Hi Craig,
I think you're right for me
Best
Jean-Marc
I think you're right for me
Best
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Jean Marc.
Likely the first time.
Anyway, I thought I was adept at forming "do" constructions, having done so here and there since 1987. But this one will not come through. Might it be something about trying to squeeze this into an "answer" command?
Craig
Likely the first time.
Anyway, I thought I was adept at forming "do" constructions, having done so here and there since 1987. But this one will not come through. Might it be something about trying to squeeze this into an "answer" command?
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Jean-marc.
I just needed rest.
Bruce.
You can do this as follows:
The "do" construction evaluates the expression twice, so LC can build the final string for the answer command to understand. Just a note, if you use "none", LC will interpret that as a "0".
But you can fool LC if you separate that "None" from the string a bit, so during the first pass at evaluation, it becomes a literal, not a constant:
Craig
I just needed rest.
Bruce.
You can do this as follows:
Code: Select all
on mouseUp
put "All or Nothing or Something" into temp
do "answer test with" && temp
end mouseUp
But you can fool LC if you separate that "None" from the string a bit, so during the first pass at evaluation, it becomes a literal, not a constant:
Code: Select all
on mouseUp
put "All or" && quote & "None" & quote && "or Something" into temp
do "answer test with" && temp
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 7240
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: building an answer string programmatically
That works fine for me, no "do" required.dunbarx wrote: ↑Mon Jan 11, 2021 6:54 pmDo you mean something like this:Code: Select all
on mouseUp put "All" into firstChoice put "None" into secondChoice answer "How many" with firstChoice or secondChoice end mouseUp
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Jacque.
But that does not quite do what the OP asked, it only places a few options into a few variables, instead of quoting each explicitly.
I think to deconstruct a SINGLE variable that contains several options requires that extra level of evaluation.
Craig
But that does not quite do what the OP asked, it only places a few options into a few variables, instead of quoting each explicitly.
I think to deconstruct a SINGLE variable that contains several options requires that extra level of evaluation.
Craig
-
- Posts: 52
- Joined: Mon Apr 06, 2020 1:19 pm
- Location: Thailand
- Contact:
Re: building an answer string programmatically
Blimey chaps! Thank you.
A special thanks to Jean for his sneaky but brilliant solution. You just made my day better and since we are unlikely to meet, I will undertake to make two people's lives better today. Let us hope that exponential growth continues for some time.
Bruce
A special thanks to Jean for his sneaky but brilliant solution. You just made my day better and since we are unlikely to meet, I will undertake to make two people's lives better today. Let us hope that exponential growth continues for some time.
Bruce
-
- Posts: 52
- Joined: Mon Apr 06, 2020 1:19 pm
- Location: Thailand
- Contact:
Re: building an answer string programmatically
Jean-Marc's "do" solution works brilliant for the example he gives: do "answer stuff with" && tOptions
But if I want to replace "stuff" with more the one word I receive the following error => execution error at line 141 (do: error in source expression)
Of course I could use underscores like this and it works "choose_one" but I fancy this is a bit ugly for non programmers.
Any ideas how I may include more than one word in Jean-Marc's otherwise 100% successful solution?
Bruce
But if I want to replace "stuff" with more the one word I receive the following error => execution error at line 141 (do: error in source expression)
Of course I could use underscores like this and it works "choose_one" but I fancy this is a bit ugly for non programmers.
Any ideas how I may include more than one word in Jean-Marc's otherwise 100% successful solution?
Bruce
Re: building an answer string programmatically
Hi, Bruce. Here's a way to invoke "answer" with multiple options, each with multiple words.
Here's a demo.
Does it give you what you need?
-- Dick
Code: Select all
command answerViaParams pPrompt, pOptions
get "answer" & quote & pPrompt & quote && "with" && quote & item 1 of pOptions & quote
repeat for each item tOption in item 2 to -1 of pOptions
get it & " or " & quote & tOption & quote
end repeat
do it
return it for value
end answerViaParams
Code: Select all
on mouseUp
answerViaParams "please choose", "all,none,something else"
breakpoint -- see "it" in the debugger's variables pane
end mouseUp
-- Dick
-
- VIP Livecode Opensource Backer
- Posts: 9676
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: building an answer string programmatically
Jean-Marc is a wonderful coder. I am the "do" guy, though. Hmph.
I mention this because "do" constructions are considered old-fashioned, and Jean-Marc is anything but that.
Anyway, the "do" construction is still priceless, at least for me, because it forces another level of evaluation, and this produces a new string that LC can then understand. This was first elucidated by Danny Goodman, with HyperCard, back in the late 80's.
LC cannot resolve a string of "choices" directly, as presented in this thread. But after "do", er, does its work, it can. The new string is identical to one that actually separates and formats the several options, as if they were entered separately in the normal course of writing an "answer" command string.
Craig
I mention this because "do" constructions are considered old-fashioned, and Jean-Marc is anything but that.
Anyway, the "do" construction is still priceless, at least for me, because it forces another level of evaluation, and this produces a new string that LC can then understand. This was first elucidated by Danny Goodman, with HyperCard, back in the late 80's.
LC cannot resolve a string of "choices" directly, as presented in this thread. But after "do", er, does its work, it can. The new string is identical to one that actually separates and formats the several options, as if they were entered separately in the normal course of writing an "answer" command string.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: building an answer string programmatically
Thank you for the flowers, but I'm a litle confused with this thread. I don't suggest using "do" in my post.
I choosed using a group way because it allows to have any LiveCode controls. I mean option menu, image, slider etc...
For example, i use this for preferences setting and to allows user to fill a field of a group "ask dialog with a screen keyboard.
Something i missed ?
Jean-Marc
I choosed using a group way because it allows to have any LiveCode controls. I mean option menu, image, slider etc...
For example, i use this for preferences setting and to allows user to fill a field of a group "ask dialog with a screen keyboard.
Something i missed ?
Jean-Marc
https://alternatic.ch