ID:2923118
 
Not a bug
BYOND Version:515
Operating System:Windows 11 Home
Web Browser:Chrome 124.0.0.0
Applies to:Dream Daemon
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
When instantiating a subtype of /image, if an argument is passed, the variables on the /image subtype will be reset to the values of variables declared on /image. This does not occur if no argument is passed.


Numbered Steps To Reproduce Problem:
1. Create an /image subtype, overriding an existing variable with a new, distinct, value. I.e. alpha = 100
2. Create a new instance of this subtype, passing a dummy argument to it.
3. Observe that the values of the variables of the subtype instance do not match the overriden variables on the subtype definition.


Code Snippet To Reproduce Problem:
/image/subtype
alpha = 100

/proc/main()
var/image/subtype/a = new /image/subtype
var/image/subtype/b = new /image/subtype("test_arg")

world.log << a.alpha
world.log << b.alpha



Expected Results:
For the initial values of the variables of the subtype to match the overriden values as declared on the subtype definition.


Actual Results:
The initial values of the variables of the subtype do not match the overriden values as declared on the subtype definition.


Does the problem occur:
Every time? Or how often? Every time.
In other games? Unknown.
In other user accounts? Unknown.
On other computers? Unknown.

When does the problem NOT occur?
N/A.

Did The Problem NOT Occur In Any Earlier Versions? If So, What Was The Last Version That Worked?
Unknown.

Workarounds:
Any logic performed in New() could be instead performed by a constructor proc for the image subtype.
Lummox JR resolved issue (Not a bug)
So this is actually not a bug, but the documentation is falling a little short and I think that's caused some confusion.

As documented, the first argument in image() can be an icon, object, or object prototype. This is not fully complete, as it can actually be anything that can be interpreted as an appearance (i.e. added to an overlays list): including a text string which represents an icon_state, or an appearance reference.

The second thing that isn't as clear from the documentation (it's inferable, but not spelled out as plainly) is that because image() is just a shortcut for new/image(), the arguments in image/New() are special and their behavior is defined internally, not by you. Therefore any subtypes of /image would behave the same way.

So this is what's happening: The text string in your example is being interpreted as a appearance built from just an icon_state. Because you've supplied an appearance to use, that's overriding all appearance data from /image/subtype.

If you had used named arguments, e.g. new/image/subtype(icon_state="test"), then the icon argument in image() would be null, which would use /image/subtype's own appearance as the base and only change the icon_state. The behavior would then be exactly what you expect.

Login to reply.