# Same class defined in more than one file

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

## 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 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".

##### 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 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 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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632934
• Total Posts
3009302
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!