|
|
|
The following page was printed from RemoteCentral.com:
Topic: | Can this be done? This thread has 8 replies. Displaying all posts. |
|
Post 1 made on Friday May 31, 2024 at 23:51 |
mpg7321 Regular Member |
Joined: Posts: | June 2020 145 |
|
|
var X = "false" CF.widget('Power').visible = X
I have tried var X = 'false' CF.widget('Power').visible = 'X' CF.widget('Power').visible = "X"
|
|
Post 2 made on Saturday June 1, 2024 at 12:48 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,059 |
|
|
I do hope you realize that for a boolean variable, you use keywords true and false without either quotes or apostrophes. You are assigning a string to variable X. The 'visible' property of a widget alwaysexpects a boolean. When a string is coerced to a boolean, the only way it will return false is if the string is empty "", even a single space will return true. If you really want to try/test things out in javascript (your first bug is in the value you assigned), I recommend [Link: playcode.io]var X = false; // See notes below //CF.widget("Power").visible = X; // Recommend using GUI.widget() GUI.widget("Power").visible = X; There are also subtle differences between GUI.widget("Power") and CF.widget("Power"). GUI.widget always returns the widget from the current page. CF.widget is able to retrieve widgets across the ConfigurationFile.
Last edited by Lyndel McGee on June 1, 2024 19:41.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
Post 3 made on Saturday June 1, 2024 at 14:39 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,059 |
|
|
On May 31, 2024 at 23:51, mpg7321 said...
var X = "false" LRM - This line assigns the string "false" to the visible property - No Good. CF.widget('Power').visible = X
I have tried var X = 'false' LRM - Both of the lines below assign string "X" to the visible property - No Good. CF.widget('Power').visible = 'X' CF.widget('Power').visible = "X"
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
OP | Post 4 made on Sunday June 2, 2024 at 02:47 |
mpg7321 Regular Member |
Joined: Posts: | June 2020 145 |
|
|
so on page load I have System.setGlobal("x", '0'); System.setGlobal("y", 'false'); from a button I call, var x = parseInt(System.getGlobal('x')) var y = System.getGlobal('y') function func() { if (x <= 1) { x = x+1; GUI.widget('Overlay_Pannel_'+x).visible = y; scheduleAfter(1, func); } else { System.setGlobal("x", 0); System.setGlobal("y", true); }} scheduleAfter(1, func); System.setGlobal("y", false); this does not work, when I retrieve it it comes through as "Null". Not entirely sure I need to do this, var x = parseInt(System.getGlobal('x')) and just do var x = System.getGlobal('x'). Not sure which way is best to set a number, I have seen examples that do it differently, such as System.setGlobal("x", '0'); or System.setGlobal("x", "0"); or System.setGlobal("x", 0);
Last edited by mpg7321 on June 2, 2024 04:19.
|
|
Post 5 made on Sunday June 2, 2024 at 18:59 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,059 |
|
|
To me, your last post is complete rhetoric and again full of errors System.setGlobal('x', 0) // Will NEVER work as number 0 is not a string. System.setGlobal('y', true) // will NEVER work as boolean true is not a string. Are you sure that you fully understand the difference between a string and a boolean in JavaScript? Have you reviewed the DEV Guide to know when to use which type? If you want to convert between string and boolean/number types then you can do something like this. var txt = "true"; // bool will only be true if txt is a string with an exact value of 'true'. var bool = (txt === "true"); var txt2 = "" + bool; var itxt = "123'; var int = parseInt(iTxt, 10) var itxt2 = "" + int
Last edited by Lyndel McGee on June 2, 2024 19:11.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
OP | Post 6 made on Sunday June 2, 2024 at 20:13 |
mpg7321 Regular Member |
Joined: Posts: | June 2020 145 |
|
|
I'm sorry, I am trying to learn but I have to learn it my way for I do not understand a lot of it, I'm not a code guy and having a lot of issues, I learn by looking at example, so sorry for asking lots of dumb questions. I don't understand what is the difference between System.setGlobal("x", '0'); and System.setGlobal("x", "0") on your example, what is to 10 for and do? var int = parseInt(iTxt, 10) as you statted, var txt = "true"; // bool will only be true if txt is a string with an exact value of 'true'. var bool = (txt === "true"); var txt2 = "" + bool; but bool will not always be 'true'. I don't understand your example. I am trying to do with global variables as well. so var txt = "true"; does not help me achieve my goal. I understand the number part I would like help getting true or false part working? setting global value with the following System.setGlobal("y", 'false'); and or System.setGlobal("y", 'true'); based on what the current state of something. I believe that it correct, Call with, var y = System.getGlobal("y") how do I convert y then so I can use it in, GUI.widget('Overlay_Pannel_'+x).visible = y;
Last edited by mpg7321 on June 2, 2024 20:28.
|
|
Post 7 made on Monday June 3, 2024 at 15:39 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,059 |
|
|
There is absolutely no difference between '0' and "0". In Javascript, strings can have either apostrophe or quote wrappers. I strongly recommend you bookmark and use this site. [Link: developer.mozilla.org]The 10 is the 2nd parameter which is a radix. If you omit the 10, then it will default to that. parseInt("10", 10) // results in 10. parseInt("10", 16) // results in 16 as you are treating the string as a hexadecimal representation. With regard to how to convert a string to a boolean, I provided the exact example you needed and how to do that conversion in my example. GUI.widget('Overlay_Pannel_'+x).visible = (y === 'true');
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
Post 8 made on Monday June 3, 2024 at 15:50 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,059 |
|
|
Put this text in a button, simulate the config and review the ProntoScript Console please. The conditions (txt === 'true') or (numberVal && true) evaluate to a boolean of either true or false depending on the value of txt or numberVal at the time of execution. System.setDebugMask(9);
var boolVar, txt,numberVar;
txt = "Mike" boolVar = (txt === 'true') // results boolVar being boolean value of false. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
txt = 'false'; boolVar = (txt === 'true') // results boolVar being boolean value of false. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
txt = 'true' boolVar = (txt === 'true') // results boolVar being boolean value of true. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
txt = "TRUE" boolVar = (txt.toLowerCase() === 'true') // results boolVar being boolean value of true. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
numberVal = 123; boolVar = Boolean(numberVal) // any non-zero numeric value is considered boolean true. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
numberVal = 0; boolVar = Boolean(numberVal) // any non-zero numeric value is considered boolean true. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
numberVal = -1; boolVar = Boolean(numberVal) // any non-zero numeric value is considered boolean true. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
numberVal = -1; boolVar = (numberVal && true) // here, numberVal is converted to boolean using type coercion because of the // logical AND && - as above, any non-zero numeric value is considered boolean // true. System.print("boolVar:" + boolVar + " typeof(boolVar):" + typeof(boolVar));
Last edited by Lyndel McGee on June 3, 2024 16:06.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
Post 9 made on Monday June 3, 2024 at 15:52 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 13,059 |
|
|
On June 2, 2024 at 20:13, mpg7321 said...
I'm sorry, I am trying to learn but I have to learn it my way for I do not understand a lot of it, I'm not a code guy and having a lot of issues, I learn by looking at example, so sorry for asking lots of dumb questions.
I don't understand what is the difference between System.setGlobal("x", '0'); and System.setGlobal("x", "0")
on your example, what is to 10 for and do? var int = parseInt(iTxt, 10)
as you statted, var txt = "true"; // bool will only be true if txt is a string with an exact value of 'true'. var bool = (txt === "true"); var txt2 = "" + bool; but bool will not always be 'true'. I don't understand your example. I am trying to do with global variables as well. so var txt = "true"; does not help me achieve my goal.
I understand the number part I would like help getting true or false part working? setting global value with the following System.setGlobal("y", 'false'); and or System.setGlobal("y", 'true'); based on what the current state of something. I believe that it correct, Call with, var y = System.getGlobal("y") how do I convert y then so I can use it in, GUI.widget('Overlay_Pannel_'+x).visible = y; Google is your friend for learning your way. Yes, there are lots of bad answers but there are lots of good ones too! [Link: google.com]
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
|
Before you can reply to a message... |
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now. |
Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.
|
|