ID:262305
 
Code:
BodyObj
var/parts[] = typesof(/BodyParts)-/BodyParts


Problem description:

The compiler is telling me that it's expecting a constant expression. I looked at the typesof() proc in the refernce, and they actually use doing this as an example, except without the -/BodyParts part. I'm assuming it has something to do with the objects being datums. But what do I know. =/

Prodigal Squirrel

Prodigal Squirrel wrote:
Code:
> BodyObj
> var/parts[] = typesof(/BodyParts)-/BodyParts
>

Problem description:

The compiler is telling me that it's expecting a constant expression. I looked at the typesof() proc in the refernce, and they actually use doing this as an example, except without the -/BodyParts part. I'm assuming it has something to do with the objects being datums. But what do I know. =/

Prodigal Squirrel

Very strange. I'm not sure what's causing your problem. However, in a few tests I've found that your code works as long as the parts list is not a member of BodyObj, or if the variable is shared between all BodyObj's.

A possible fix would involve using either the "global" or "static" keywords, if it works for what you want. Global would make the variable shared between all instances of BodyObj. I forget what static does since it's fairly old and no longer in the reference, but it does something similar. :) Here's some example code:
BodyObj
var/global/parts[] = typesof(/BodyParts)-/BodyParts


You could also create/populate the list at runtime, in the BodyObj/New() procedure. That way you don't need to worry about the compiler warning at all.
In response to Jon88
Perhaps I've found a bug then?

The global or static keywords wouldn't have the effect I need here. And, originally, I filled the list through New(), but thought I could find a prettier, and shorter way of doing it.

Prodigal Squirrel