ID:1390287
 
BYOND Version:500
Operating System:Windows 7 Home Premium 64-bit
Web Browser:Firefox 24.0
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:
When I include the line:
atom/icon_state=""

It still defaults to null at runtime. This would be fine if not for how the icon() proc interacts with icon_states. I want to extract only the objects current icon state, but icon(icon,null) seems to extract all the icon's states rather than just the specific one. (Which isn't the issue, the issue is that the icon_state is null in the first place)

Numbered Steps to Reproduce Problem:
1:Set icon_state=""
2:Start the game
3:Test icon_state on an object.
4:Discover that it reads null.
5:Discover also that it doesn't like the icon() proc.


Code Snippet (if applicable) to Reproduce Problem:
atom/icon='TestIcon.dmi'
//Test icon is an icon with "","Other", and "Other2" for icon_states, so we can see the difference.
mob
icon_state=""
verb/test_null()
if(icon_state==null) src<<"Null"
else src<<"Not Null"
verb/get_file() src<<ftp(icon(icon,icon_state))


Expected Results:
get_file() would send an icon with just the "" state, and get_state() would return "Not Null".

Actual Results:
get_file() sends an icon with all the icon states of the file, and get_state() returns "Null".

Does the problem occur:
Every time? Or how often?
Always
In other games?
I encountered the error in my own game, and then tested in a separate library to repeat see if I could repeat the issue, and did.
In other user accounts?
I didn't see a reason to test.
On other computers?
I also failed to see a reason to test, though also didn't have access to one.

When does the problem NOT occur?
Always seems to.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
Never tested.

Workarounds:
When I change icon_state="" during run-time rather than directly applying to an object's type in the code it works perfectly, but I don't care to have to do this.

I think I see what you're getting at.

From what I'm seeing, the fact that icon_state="" is changed to icon_state=null at compile-time appears to be a deliberate choice made in the compiler. I'm not sure if there's a reason for this that might negatively impact any games if changed; my gut says probably not, but it warrants further study.

Because the behavior in question is deliberate, I'm not sure this strictly qualifies as a bug, but I'll leave it open regardless while I investigate.
Last I checked, emptystring and null are equal, and literally represented as the same thing internally, specially in the DMB format in multiple places
Well, I put it as a bug as one would 'expect' that setting icon_state="" would in fact set it to "" instead of null per how it does such for other vars. If I posted this in the wrong forum section, I apologize, I'm rather new to the BYOND forums.

As of Toba's comment,
I'm not 100% sure what you're talking about as I'm bad with terms, but the following does give output if it's what you're talking about.
mob/verb/test() if(null!="") src<<"They are not equal"

I've done a lot of code that wouldn't work if it didn't work that way, so I would sure hope it does.
I don't think you posted this in the wrong section; the question at hand is whether the compiler's behavior is a bug or something we should keep.

Null and the empty string are not equal, although both will return false in an if() check (as will the number 0).

That said, displaying atoms at runtime treats "" and null as equivalent where icon_state is concerned. This may be the only reason the compiler changes "" to null when compiling atom.icon_state; if so I don't think it's a good enough reason, and it seems really unlikely to break anything if I change it. I don't want to change it without being sure, however.
Ah. Well thank you for looking into it so quickly.
I would recommend as a workaround, whether this does get classified as a bug and fixed or closed as a non-bug, not relying on atom.icon_state to know the difference between "" and null. Instead, when you send the state to the icon() proc, just use (icon_state||""). The result of the || operator will be either the first true value encountered, or the last false value, so it should give you the empty string when icon_state reads as null.
Oh wow, thanks for the tip. I always thought that it just returned 1 or 0 depending on if either side was true. Shows how much I pay attention.