[comp.sys.mac.hypercard] Are computed 'answer's possible?

shap@sfsup.UUCP (J.S.Shapiro) (01/09/88)

I have a hack for which I would like to use a computed 'answer'.
That is, I want to determine what the options given in the 'answer'
command are by some calculations rather than by stating them
a priori.

Example: Depending on the value of a number, item X of the
answer options might or might not show up, for some large
set of possible combinations of X and other inputs.

Jon

aisl@ur-tut.UUCP (Larry Landry) (01/15/88)

In article <2582@sfsup.UUCP> shap@sfsup.UUCP (J.S.Shapiro) writes:
>I have a hack for which I would like to use a computed 'answer'.
>That is, I want to determine what the options given in the 'answer'
>command are by some calculations rather than by stating them
>a priori.
>
>Jon

HyperTalk allows you to generate a script in a variable and then execute
that script.  The following code will execute an answer with variable
options.

on varAnswer count, question, reply1, reply2, reply3
  -- the answer command with varible number of commands
  -- pass three replys and reduce count if you don't want all to appear
  
  -- build the command

  put "answer" && quote & question & quote into myCommand
  if count > 0 then
    put " with " & quote & reply1 & quote after myCommand
    if count > 1 then
      put " with " & quote & reply1 & quote after myCommand
      if count > 2 then
        put " with " & quote & reply1 & quote after myCommand
      end if
    end if
  end if

  do myCommand
end varAnswer

Simply modify this to your application.


Larry Landry

aisl@ur-tut.UUCP (Larry Landry) (01/15/88)

I had a minor error in the script that I posted.  I placed with
between the replies instead of or.  The script should read:

on varAnswer count, question, reply1, reply2, reply3

  ...

  put "answer" && quote & question & quote into myCommand
  if count > 0 then
    put " with " & quote & reply1 & quote after myCommand
    if count > 1 then
      put " or " & quote & reply1 & quote after myCommand
      if count > 2 then
        put " or " & quote & reply1 & quote after myCommand


Sorry for the error.


Larry Landry