Help: Returns window id for current script.

I do this:
dcc chat %nick | var %wid = $chat($chat(0)).wid
..and I store that %wid in a custom window together with some other data.

Then, in the
on ^*:OPEN:=:{ ... }
event, I use $wid to get the attached data from the @window.

But, it's not the same one. For ex, it stores 1804 after /dcc chat and in the on open, $wid is 54, being the one of the status window.

What am I doing or assuming wrong here?