Convert Var/Text to String for get-method

PennController for IBEX Forums Support Convert Var/Text to String for get-method

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10523
    walch
    Participant

    Hello!
    I want to define a variable (or text) that I can change multiple times (10x). The variable should carry the name of different canvas objects and be read in by getCanvas() (see below). I assume that an object of type Var/Text is returned and getCanvas asks for a string. Unfortunately, none of my attempts at a solution work! Could you please help me?
    Thanks!
    Christin

    newButton("B1", "+"),                                                   
    newButton("B2", "+"),
    newCanvas("C1",780,20 )
      .settings.add( "right at 100%", "middle at 50%", getButton("B1").print())
      .css( "border" , "solid 1px black" ),    
    newCanvas("C2",780,20 )
      .settings.add( "right at 100%", "middle at 50%", getButton("B2").print())
      .css( "border" , "solid 1px black" )
      .settings.hidden(),
    newVar("canvasnr", "C2"),
    getButton("B1")
      .callback(getCanvas(getVar("canvasnr")).settings.visible()), //here is the problem
    #10526
    Jeremy
    Keymaster

    Hello Christin,

    You cannot use a reference to a PennController element inside a getX command, because the execution of (plain) JavaScript is immediate, but that of PennController commands is delayed

    What you can do is use a Function element in which you manipulate the PennController elements by accessing their methods and attributes:

    getButton("B1")
      .callback( newFunction( ()=>{
        try { getCanvas( getVar("canvasnr")._element.value ).visible()._runPromises(); } 
        catch (e) { }
      }).call() )

    Jeremy

    #10545
    walch
    Participant

    Thanks a lot! It works! But if I now change the variable at the same time, it only works for the first button and not for any others. What is the reason for this?

     getButton("B1")
      .callback( newFunction( ()=>{
        try { getCanvas( getVar("canvasnr")._element.value ).visible()._runPromises();
        setVar("canvasnr", C3); // set the value of canvasnr to 3
        }
        catch (e) { }
      }).call() ),
            getButton("B2")
      .callback( newFunction( ()=>{
        try { getCanvas( getVar("canvasnr")._element.value ).visible()._runPromises();
        setVar("canvasnr", C4); // set the value of canvasnr to 3
        }
        catch (e) { }
      }).call() ),
            getButton("B3")
      .callback( newFunction( ()=>{
        try { getCanvas( getVar("canvasnr")._element.value ).visible()._runPromises();
        setVar("canvasnr", C5); // set the value of canvasnr to 3
        } // ...
    #10548
    Jeremy
    Keymaster

    There is no javascript function called setVar. What you can do is:

    getButton("B1")
      .callback( 
        newFunction( ()=>{
          try { getCanvas( getVar("canvasnr")._element.value ).visible()._runPromises(); }
          catch (e) { }
        }).call()
        ,
        getVar("canvasnr").set("C3")
      )

    Jeremy

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.