Same class defined in more than one file

Started by
3 comments, last by saejox 11 years, 10 months ago
Hi,


Is it possible to define a class more than once? (same module)

some thing like this:
file1.as

class Player : PlayerBase
{
int foo;
}

file2.as

class Player : PlayerBase
{
int bar;
void Foobar
{
int foobar = foo + bar;
}
}


i have tried it, but it seems this is not the syntax. (or cant be done at all?)
this is important because, user mods would be much easier to develop if i allow them to define methods&members without forcing them to edit one file.
it also makes getting around the class much harder.

how can i achieve this? (i currently send handles to global functions in other files e.g void Func(Player @pc))

thank you.
Advertisement
That's sort of a strange approach. It sounds like what you might need is a "component system", whereby multiple behaviors represented by different classes can be bound together into single "objects".

That's sort of a strange approach. It sounds like what you might need is a "component system", whereby multiple behaviors represented by different classes can be bound together into single "objects".


i do it all time in c++.
headers in one file, implementation in many files.
say player has physics, gui, movement etc.. functions. i would like them to be in separate files, much easier to manage that way.
A script section must contain only complete entities. So it is not possible to declare part of the class in one section and the other part in another section.

What you can do is to use pre-processing to concatenate multiple files into a single section that forms the complete class declaration. If you do this you'll probably have to translate line and section name for error messages back to the original files in the MessageCallback.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game


A script section must contain only complete entities. So it is not possible to declare part of the class in one section and the other part in another section.

What you can do is to use pre-processing to concatenate multiple files into a single section that forms the complete class declaration. If you do this you'll probably have to translate line and section name for error messages back to the original files in the MessageCallback.


if i will have some time left, i will do that.

for now, i will continue sending class handles as parameters to other functions.

thank you.

This topic is closed to new replies.

Advertisement