walch

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Multiple use of the same object #10688
    walch
    Participant

    Hello Jeremy,
    Thank you for your answer! I didn’t express myself precisely enough.

    I have 9 buttons (speed, consumption, hp,… – like on a car quartet card) that generate text on the left or right of one of 10 canvases, depending on a variable, which are filled one after the other.
    So I have a total of 18 possible pieces of text that the user can generate by pressing one of the buttons. Each of these 18 pieces of text should be able to appear several times on one of the 20 possible places (left or right on the respective canvas).
    My question now is: Can I place 20 hidden text elements (instead of preparing 20*9 elements) on the canvas and pass them the corresponding selected text element? I know there is no set method for the text elements, but can I work around this?
    This is a part of the code to make my description easier to understand.
    Thanks a lot!
    Christin

    newButton ("PS", "Leistung "+ "<br>"+ variable.LeistungPS  + " PS")
    ,
    //...
    newText("PS1", "Der "+variable.model + " hat eine Leistung von " + variable.LeistungPS + " PS")
    ,
    newText("PS2", " er hat eine Leistung von " + variable.LeistungPS + " PS.")
    ,
     //...
    newCanvas("canvas1",780,20 )
        .settings.add( "right at 100%", "middle at 50%", getButton("+1").print())
        .css( "border" , "solid 1px black" )    
        ,
    newCanvas("canvas2",780,20 )   
    	.settings.add( "right at 100%", "middle at 50%", getButton("+2").print())
        .css( "border" , "solid 1px black" )
        .settings.hidden()
        ,
    //...
    newCanvas("canvas10",780,20 )
        .css( "border" , "solid 1px black" )
        .settings.hidden()
    ,
    //...
    newVar("site", "left at 0%"), //left or right on the canvas
    newVar("mid", "middle at 50%"),
    newVar("nr", "1"),//Text1 or Text2
    newVar("canvasnr_button", "canvas1"), //canvas where the text should appear, changes when Button "+" is pressed
    
    getButton("PS")
    	.callback( newFunction( ()=>{
    	try { getCanvas(getVar("canvasnr_button")._element.value).add( getVar("site")._element.value, 
                                                                           getVar("mid")._element.value, 
                                                                           getText("PS"  + getVar("nr")._element.value))
                  ._runPromises();
        }
        catch (e) { }
    	}).call(),
           getVar("mid").set("middle at 50%"),getVar("nr").set("2"),
           getVar("site").set("left at 55%")
        ),
    //...
    in reply to: Convert Var/Text to String for get-method #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
        } // ...
Viewing 2 posts - 1 through 2 (of 2 total)