Hello,
I want to have a class where each instance always contains certain objects. As if they were added with the + syntax to the instance.
I tried:
class test : Actor
foo = new TestObject()
foo.location = self
;
But the compiler throws lots of errors on line 3. It seems, that it cant parse the . which causes lots of other parsing errors.
Using the constructor in some way isn’t a solution since I will need to write and read properties of foo in tant class.
Somehow I get a “[Runtime error: wrong number of arguments” error from the VM now.
Using the code you provided I can compile without warning, but the object is never initialized.
The constructor is never called(breakpoint in constructor).
So I overwrote the desc of the payer to call the working desc of the TestObject.
class TestObject: Possession, Thing, Component
{
construct(initial_location)
{
location = initial_location;
}
}
class Test: Actor
{
foo = new TestObject(self);
desc = foo.desc;
}
+ me: Test
;
The Line the error suposely happens in is the last line of the .t file that contains the TestObject class. It consists of one “;” and nothing else.
Using breakpoints I found the erorr in the " location = initial_location;" line, but that makes no sense to me.
Also, if the code you posted really looks like that:
[code]class Test: Actor
{
foo = new TestObject(self);
desc = foo.desc;
}
me: Test
;[/code]
Then this will of course not work (but compile fine), since you’re trying to put the ‘me’ object (using the ‘+’ syntax) inside something that does not derive from a BasicLocation class (like Room.)
@RealNC no I didn’t make that mistake, in my project nearly every paragraph of the code I posted is in its own .t file.
I finally found the error.
Custom constructors arn’t properly inherited!
In my code I din’t have an object of the TestObject class, but one that inherited only testobject and defined name (and in the future additional code). If you add:
to that class everything suddenly works.
The debugger “step within” stepped into the custom constructor of the parrent class, but the stack listed a call to a constructor without arguments. Thus “Runtime error: wrong number of arguments”.
It isn’t reproduceble in the simplyfied verson, so there are probably more conditions to triggering that error than I found, but it works now.