problems sending arguments to function in XML file

Using XMLHttpRequest() to configure entire ToolBook pages.

problems sending arguments to function in XML file

Postby John Robin Dove » Tue Jul 02, 2019 10:50 am

Hi Clifton,
Thanks for the update.

I'm still plodding on, 1 step forward 2 steps back most of the time. To reduce the size of my TBK file and make the Dump Book Actions function work again I want to put as many of my shared actions as possible into an XML file. Working without an action scripts TXT file makes debugging very difficult.

I cannot manage to pass arguments to my XML defined function. Here is the shared action I am trying to replace. There are no problems with this version.
Image
Because I don't know exactly when and where it is used in the program I need to keep part of the shared script like this.
Image
My XML version looks like this.
Code: Select all
<function name="setPauseTime" event="" params="reply,replyN1,replyN2,preview,MSecs,unit,currentTrigger,txt">
        <![CDATA[
        alert (replyN1 + ' ' + replyN2 + ' ' + reply); //Cancel,No limit!!
          if (reply == replyN1 || reply == replyN2)       
          {
          tbfunction_pgTBObjSet("info","user","nextAction," + 8);
          tbfunction_pgTBObjSet("info","user","stage," + 1);
          tbfunction_showRequest("294`1","190`1","180`1"); //Do you want the media player to continue without pausing?!!
          }
          else //Pause time is in reply.!!
          {
            if (preview == 3)
            {
            tbfunction_pause1(reply,MSecs,unit,currentTrigger)
            }
            else if (preview == 4)
            {
            tbfunction_pause2(reply,MSecs,unit,txt,currentTrigger)
            }
          }
        ]]>
    </function>

And it returns this
Image
which is not helpful. I notice that in your javascript example you put square brackets around the argument list. Would it perhaps work if I added "[" & at the beginning of the args variable and & "]" at the end? This is about the only thing I have not tried yet. I should have tried this before I put the original shared action back (just to end on a positive outcome). I suspect the mixture of text and integers is causing the problem.

Thanks for your time
John
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: problems sending arguments to function in XML file

Postby John Robin Dove » Wed Jul 03, 2019 6:27 am

I have found a way round this. I send the variables as one comma separated string and then use pgSplitToArray() to separate them.
Code: Select all
 <function name="getParameters" event="" params="p1">
        <![CDATA[
        var myArray = [];
        myArray = tbfunction_pgSplitToArray(p1);
        var i;
          for (i = 0; i < myArray.length; i++) {
          alert(myArray[i]);
          }
        ]]>
    </function>


UPDATE
Before using the integers arithmetically I have to multiply them by 1 e.g. myArray[3] = myArray[3] * 1;
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: problems sending arguments to function in XML file

Postby Clifton » Wed Jul 03, 2019 1:37 pm

The PowerPac Help API indicates that when using pgTBObjSet() to call a function, it is a good idea to put the arguments (parameters) in an array.
Example:
    Consider this function which is defined in an XML file:
    <myObjectName>
    <function name="myTask" event="" params="p1,p2,p3,p4">
    <![CDATA[
    alert( p1 + " > " + p2 + " > " + p3 ); //Debuggins parameters
    //Body of function goes here
    ]]>
    </function>
    </myObjectName>
     

    To call this using pgTBObjSet():
    tbfunction_pgTBObjSet( "myObjectName", "myTask", [ "p1 is a string", 1234, { first : "Clifton", last : "Sleger" } ] );
     

    The parameters sent to the myTask( p1, p2, p3 ) custom function include p1 as a string, p2 as an integer, and p3 as an object with properties.
    The debug alert will display the following:
    p1 is a string > 1234 > [object]
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: problems sending arguments to function in XML file

Postby John Robin Dove » Thu Jul 04, 2019 3:14 am

My apologies. This was one of the methods I had been trying. Unfortunately this part of my XML code contained an error which I only found this morning. I confused javascript with TB actions code and wrote & instead of +.

There is another snag. I am trying to reduce the code in the tbk. Putting six variables into an array in TB requires six lines of code. I can't see a way round this so for the moment I shall continue to use the single parameter system described above.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am


Return to XML Configurations – Plugin Examples

Who is online

Users browsing this forum: No registered users and 5 guests

cron