• Advertisement
Sign in to follow this  

Same class defined in more than one file

This topic is 2089 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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. Edited by saejox

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement