Calling commands and functions from a variable

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Calling commands and functions from a variable

Post by dunbarx » Thu Sep 17, 2015 7:46 pm

Couldn't you load the answers into an array? (pseudo)

Code: Select all

put the selectedLines of fld "answers" into answerArray[series][questionNumber][question][answerList} 
As I read your post with the six questions, it seems like you would step through the suite of questions and end up with a dataSet.

What you do with that dataSet is another story, but isn't this basically what you need? If so, you simply start the question sequence, run it through, and then deal with the data. Where are you stuck? Running the sequence gadget?

Craig

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: Calling commands and functions from a variable

Post by pink » Thu Sep 17, 2015 8:34 pm

okay, I started thinking about how to break down complex logic, and I was thinking this... seperate the action from the evaluation, for example

findTruth "q8","Q","greaterequal",9,"V",skipToQ8B
findTruth "q8","Q","lessequal",2,"V",skipToQ8A

Code: Select all

command findTruth  pVal1 pVal1src pOperator pVal2 pVal2Src pHolder pOverwriteTruth
     if pOverwriteTruth is not true then
          put getVar(pHolder) into tCheck
          if tCheck is true then exit findTruth
     end if
     put false into temp
     if pVal1 is "current" then put field "qLabel" into pVal1 ---tossed this in to make logic reusable in questionnaire
     if pVal1src is "S" then put wreckord["sein"][pVal1] into tX   --sample data
     if pVal1src is "Q" then put getCodes(pVal1) into tX  --question data
     if pVal1src is "V" then put getVar(pVal1) into tX  --generated variable
     
     if pVal2src is "S" then put wreckord["sein"][pVal2] into tY
     if pVal2src is "Q" then put getCodes(pVal2) into tY
     if pVal2src is "V" then put getVar(pVal2) into tY
     if pVal2src is "K" then put pVal2 into tY  --constant value
     
     repeat for each item tCode in tX
          switch pOperator
               case empty
                    break
               case "anytrue"  --for generated vars that are booleans
                    if tX is true or tY is true then put true into temp
                    break
               case "alltrue"  --for generated vars that are booleans
                    if tX is true and tY is true then put true into temp
                    break
               case "text"  --specifically for sample vars
                    if tCode is tY then put true into temp
               case "among"   --specifically for mult response pVal2Src
                    if tCode is among the lines of tY then put true into temp
                    break
                    --none of the below cases will work if pVal2 is a multiple response question
               case "equal"
                    if tCode = tY then put true into temp
                    break
               case "notequal"
                    if tCode <> tY then put true into temp
                    break
               case "greaterequal"
                    if tCode >=  tY then put true into temp
                    break
               case "lessequal"
                    if tCode <= tY then put true into temp
                    break
               case "greater"
                    if tCode > tY then put true into temp
                    break
               case "less"
                    if tCode <  tY then put true into temp
                    break
          end switch
          if temp is true then exit repeat
     end repeat
     addVar pHolder,temp
end findTruth

command addVar pName pVal
     put pVal into wreckord["data"][pName]
end addVar

function getVar pName
     return wreckord["data"][pName]
end getVar

So running these 2 commands will net me two variables named skipToQ8B and skipToQ8A which will have a value of either true or false.
I can create seperate commands that will act if things are true.

am I over thinking this?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: Calling commands and functions from a variable

Post by pink » Thu Sep 17, 2015 8:41 pm

dunbarx wrote:Couldn't you load the answers into an array? (pseudo)

Code: Select all

put the selectedLines of fld "answers" into answerArray[series][questionNumber][question][answerList} 
As I read your post with the six questions, it seems like you would step through the suite of questions and end up with a dataSet.

What you do with that dataSet is another story, but isn't this basically what you need? If so, you simply start the question sequence, run it through, and then deal with the data. Where are you stuck? Running the sequence gadget?

Craig
I'm not sure what you're asking here, but in fact I do have the answers in an array that looks someting like this:
wreckord["data"][ques#][keys][values]
so if the answer to "q1" is "no" it would be wreckord["data"]["q1"]["c2"]["No"]
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Post Reply