PennController for IBEX › Forums › Support › Convert Var/Text to String for get-method
Tagged: type shifting
- This topic has 3 replies, 2 voices, and was last updated 1 year, 6 months ago by Jeremy.
-
AuthorPosts
-
May 8, 2023 at 2:59 pm #10523walchParticipant
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!
ChristinnewButton("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
May 9, 2023 at 5:06 am #10526JeremyKeymasterHello 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 delayedWhat 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
May 10, 2023 at 4:15 am #10545walchParticipantThanks 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 } // ...
May 10, 2023 at 6:45 am #10548JeremyKeymasterThere 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
-
AuthorPosts
- You must be logged in to reply to this topic.