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.

Comparing event.dst to a variable
#1
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?
Reply
#2
(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.
------------------------------
Ctrl+F5
Reply
#3
(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.
Reply
#4
But I just tried it and it works fine. Try from scratch Smile Make sure you disabled other scripts with this tag.
------------------------------
Ctrl+F5
Reply
#5
(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.
Reply


Forum Jump: