This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

if (two conditions) then
#1
Hi,

I have made a script with two conditions that need to be fulfilled before doing something. I have tried everything bt it is not working. There are no syntax errors now and I disable/enable every time I save scripts just to be sure.

The script reads a value from a illumination sensor and status from a light object. Then it compares the two and writes to the same light object. Here it is:


Code:
illumivalue = grp.getvalue('32/1/3')
switchvalue = grp.getvalue('0/4/10')
if (illumivalue <= 5 and switchvalue == 0) then
  grp.write('0/4/10',1)
elseif (illumivalue >= 5 and switchvalue == 1)
  then grp.write('0/4/10',0)
end
Reply
#2
(11.03.2018, 00:04)02dag Wrote: Hi,

I have made a script with two conditions that need to be fulfilled before doing something. I have tried everything bt it is not working. There are no syntax errors now and I disable/enable every time I save scripts just to be sure.

The script reads a value from a illumination sensor and status from a light object. Then it compares the two and writes to the same light object. Here it is:


Code:
illumivalue = grp.getvalue('32/1/3')
switchvalue = grp.getvalue('0/4/10')
if (illumivalue <= 5 and switchvalue == 0) then
  grp.write('0/4/10',1)
elseif (illumivalue >= 5 and switchvalue == 1)
  then grp.write('0/4/10',0)
end

Change this line:
Code:
if (illumivalue <= 5 and switchvalue == false) then
Done is better than perfect
Reply
#3
(11.03.2018, 00:21)buuuudzik Wrote:
(11.03.2018, 00:04)02dag Wrote: Hi,

I have made a script with two conditions that need to be fulfilled before doing something. I have tried everything bt it is not working. There are no syntax errors now and I disable/enable every time I save scripts just to be sure.

The script reads a value from a illumination sensor and status from a light object. Then it compares the two and writes to the same light object. Here it is:


Code:
illumivalue = grp.getvalue('32/1/3')
switchvalue = grp.getvalue('0/4/10')
if (illumivalue <= 5 and switchvalue == 0) then
  grp.write('0/4/10',1)
elseif (illumivalue >= 5 and switchvalue == 1)
  then grp.write('0/4/10',0)
end

Change this line:
Code:
if (illumivalue <= 5 and switchvalue == false) then

Thank you very much. This worked, but I am puzzled. I thought that you could use both 0/1 or /true/false for things like this? Never thought of the latter for this script though.
Reply
#4
(11.03.2018, 10:59)02dag Wrote:
(11.03.2018, 00:21)buuuudzik Wrote:
(11.03.2018, 00:04)02dag Wrote: Hi,

I have made a script with two conditions that need to be fulfilled before doing something. I have tried everything bt it is not working. There are no syntax errors now and I disable/enable every time I save scripts just to be sure.

The script reads a value from a illumination sensor and status from a light object. Then it compares the two and writes to the same light object. Here it is:


Code:
illumivalue = grp.getvalue('32/1/3')
switchvalue = grp.getvalue('0/4/10')
if (illumivalue <= 5 and switchvalue == 0) then
  grp.write('0/4/10',1)
elseif (illumivalue >= 5 and switchvalue == 1)
  then grp.write('0/4/10',0)
end

Change this line:
Code:
if (illumivalue <= 5 and switchvalue == false) then

Thank you very much. This worked, but I am puzzled. I thought that you could use both 0/1 or /true/false for things like this? Never thought of the latter for this script though.

You can check that type(false) is 'boolean' and type(0) is 'number'. If you aren't sure of type of variable you can use toboolean function. Check this:
Code:
log(type(false))

log(type(0))

log(type(toboolean(0)))
Done is better than perfect
Reply
#5
Hi,

true/false or 1/0 does not matter for writing, when comparing something it (offcourse) cannot be both (:

Tip: If result of a condition is not what you expect, log the variables to see what is going on..

BR,

Erwin
Reply


Forum Jump: