Board index
Programs with AI or Rules Enforcement
Magic: The Gathering - Duels of the Planeswalkers
Programming Talk



nil is nil, right?
Moderator: CCGHQ Admins
nil is nil, right?
by Eglin » 21 Mar 2012, 01:08
Hi guys,
I'm having a little trouble understanding something.
Consider the following:
However, if I try to use the same mechanism in a trigger, I see different behavior:
My only guess is that the game's logic in this case considers anything != true to be false, which is a fallacy. If anyone can shed a little light on this, I'd be most grateful.
Thanks in advance,
Eglin
I'm having a little trouble understanding something.
Consider the following:
- Code: Select all
store = Storage(Object)
store.set("bar")
if store.get("foo") then print "bar" end
However, if I try to use the same mechanism in a trigger, I see different behavior:
- Code: Select all
<TRIGGER value="DOESN'T MATTER WHICH">
return (Storage(Object()).get("target") ~= nil)
</TRIGGER>
- Code: Select all
<TRIGGER value="DOESN'T MATTER WHICH">
return (Storage(Object()).get("target"))
</TRIGGER>
My only guess is that the game's logic in this case considers anything != true to be false, which is a fallacy. If anyone can shed a little light on this, I'd be most grateful.
Thanks in advance,
Eglin
Re: nil is nil, right?
by thefiremind » 21 Mar 2012, 09:10
I often forget to add "~= 0" after the tests when I write code quickly, and this always leads to code that doesn't work. I'm not an expert in LUA and I learned the most by observing other code, so I don't know the reason. I can only imagine that LUA always needs explicit evaluations.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 722 times
Re: nil is nil, right?
by Eglin » 21 Mar 2012, 17:59
Everything I've read about the language says that false is defined as nil and true is defined as not false. It's why "bar" prints above. What we're seeing seems to be an inconsistency, which is why it's so confusing.thefiremind wrote:I often forget to add "~= 0" after the tests when I write code quickly, and this always leads to code that doesn't work. I'm not an expert in LUA and I learned the most by observing other code, so I don't know the reason. I can only imagine that LUA always needs explicit evaluations.
Re: nil is nil, right?
by nabeshin » 23 Mar 2012, 17:21
not so confusing, c-part of game wait from your lua-script SOME important...
and you disappointed her.
and you disappointed her.
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests