Logic Machine Forum
Comparing event.dst to a variable - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Comparing event.dst to a variable (/showthread.php?tid=1163)



Comparing event.dst to a variable - baggins - 04.01.2018

Hi,

I have a couple of addresses with the same tag and an event script which is attached to those addresses.
When the event script is executed is does something different depending on the address.
Initially I had the following (simplified):

Code:
c = event.dst
if c == '1/1/1' then log('a')
elseif c == '2/2/2' then log('b')
end


That worked. However I wanted to use a variable for the addresses because this script needs to run on different LM and the addresses are different.
So I tried:



Code:
a = '1/1/1'
b = '2/2/2'
c = event.dst
if c == a then log('a')
elseif c == b then log('b')
end

This does not work.

if I use a table instead of a and b like
Code:
d = {'1/1/1', '2/2/2'}
c = event.dst
if c == d[1] then log'a')
elseif c == d[2] then log('b')
end
This works.

I'm most surely overlooking the obvious?


RE: Comparing event.dst to a variable - Daniel - 04.01.2018

(04.01.2018, 14:43)baggins Wrote: Hi,

I have a couple of addresses with the same tag and an event script which is attached to those addresses.
When the event script is executed is does something different depending on the address.
Initially I had the following (simplified):

Code:
c = event.dst
if c == '1/1/1' then log('a')
elseif c == '2/2/2' then log('b')
end


That worked. However I wanted to use a variable for the addresses because this script needs to run on different LM and the addresses are different.
So I tried:



Code:
a = '1/1/1'
b = '2/2/2'
c = event.dst
if c == a then log('a')
elseif c == b then log('b')
end

This does not work.

if I use a table instead of a and b like
Code:
d = {'1/1/1', '2/2/2'}
c = event.dst
if c == d[1] then log'a')
elseif c == d[2] then log('b')
end
This works.

I'm most surely overlooking the obvious?
hm..
your first script work but the second with table should not as you miss ( in third line next to log.


RE: Comparing event.dst to a variable - baggins - 04.01.2018

(04.01.2018, 16:25)Daniel. Wrote:
(04.01.2018, 14:43)baggins Wrote: Hi,

I have a couple of addresses with the same tag and an event script which is attached to those addresses.
When the event script is executed is does something different depending on the address.
Initially I had the following (simplified):

Code:
c = event.dst
if c == '1/1/1' then log('a')
elseif c == '2/2/2' then log('b')
end


That worked. However I wanted to use a variable for the addresses because this script needs to run on different LM and the addresses are different.
So I tried:



Code:
a = '1/1/1'
b = '2/2/2'
c = event.dst
if c == a then log('a')
elseif c == b then log('b')
end

This does not work.

if I use a table instead of a and b like
Code:
d = {'1/1/1', '2/2/2'}
c = event.dst
if c == d[1] then log'a')
elseif c == d[2] then log('b')
end
This works.

I'm most surely overlooking the obvious?
hm..
your first script work but the second with table should not as you miss ( in third line next to log.

That is a typo in the example... In reality this works, but the second script with a 'normal' variable does not work and I cannot figure out why.


RE: Comparing event.dst to a variable - Daniel - 04.01.2018

But I just tried it and it works fine. Try from scratch Smile Make sure you disabled other scripts with this tag.


RE: Comparing event.dst to a variable - baggins - 04.01.2018

(04.01.2018, 16:49)Daniel. Wrote: But I just tried it and it works fine. Try from scratch Smile Make sure you disabled other scripts with this tag.

Hm, I retyped the test script and it worked...

I then reran the original test script and it failed. I then retyped the address assignment and then the script ran. There must have been a hidden extraneous character in the original address that didn't show up in the log (I logged every variable and could not see any difference in the strings...)
Thanks for your help.