Hi,
All the extension files I see in sfsExtension folder have their logic written in the same file.
Is there a way to encapsulate server logic in classes?
I tried importing my classes into the "extension".as file with the four core functions but I was getting an syntax error from SFS complaining about the import.
Did I miss something obvious?
Thanks.
How do you encapsulate extension logic?
-
- Posts: 9
- Joined: 09 Apr 2008, 22:29
- Contact:
-
- Posts: 9
- Joined: 09 Apr 2008, 22:29
- Contact:
Yes, you can make classes, you can declare them in external files and import them into your main extension file.
By default each extension file should be located under sfsExtensions/ or any subfolder created under that path.
You could have this scenario:
sfsExtensions/classes/myClasses1.as
sfsExtensions/classes/myClasses2.as
sfsExtensions/classes/MainExtension.as
in MainExtension.as you put this code at the beginning:
By default each extension file should be located under sfsExtensions/ or any subfolder created under that path.
You could have this scenario:
sfsExtensions/classes/myClasses1.as
sfsExtensions/classes/myClasses2.as
sfsExtensions/classes/MainExtension.as
in MainExtension.as you put this code at the beginning:
Code: Select all
#include "classes/myClasses1.as"
#include "classes/myClasses2.as"
...
rest of the code
...
-
- Posts: 9
- Joined: 09 Apr 2008, 22:29
- Contact:
Hi Lapo,
I tried using include to import my own classes, but the SFS console complains about the keyword "class". It says that it is a reserve word and threw an error.
If you want to look at my test code, here it is:
I tried using include to import my own classes, but the SFS console complains about the keyword "class". It says that it is a reserve word and threw an error.
If you want to look at my test code, here it is:
Code: Select all
class TestClass
{
function TestClass()
{
trace("contructing testclass");
}
}
Classes are not supported like that in AS1/Javascript. Here is a good tutorial on using classes that you can follow:
http://www.xml.com/pub/a/2006/06/07/obj ... cript.html
http://www.xml.com/pub/a/2006/06/07/obj ... cript.html
Re:
BenV wrote:Classes are not supported like that in AS1/Javascript. Here is a good tutorial on using classes that you can follow:
http://www.xml.com/pub/a/2006/06/07/obj ... cript.html
Is this still the case ?
Are sfsExtensions still AS1 ?
(it seems to be, as I just tried the above class example and got the same error).
Mike
Re: How do you encapsulate extension logic?
If you're using SmartFoxServer PRO, as I presume, then yes you can use AS/JS or Python or Java.
Re: How do you encapsulate extension logic?
Lapo wrote:If you're using SmartFoxServer PRO, as I presume, then yes you can use AS/JS or Python or Java.
Yes I'm using the current Pro server.
What level of AS is supported by the server-extensions?
Is the "external class file / syntax" supported ?
thx
Mike
Re: How do you encapsulate extension logic?
It is compatible with ECMA 262 specs. Or Javascript in other words.
So it's not like Actionscript 3.
If you wish to use something like AS3 then I'd highly recommend using straight Java. AS3 is heavily "inspired" by Java. Same OOP paradigm, syntax etc... if you are familiar with AS3 moving to Java is a no brainer, plus you'll find a more rich set of API.
Back to the AS1/JS question you can import other source files using the "include" directive. You can learn all the details by taking a look at Section 7 of the SFS PRO docs: http://www.smartfoxserver.com/docs/1x/
If you haven't started developing yet, my suggestion is to also take a look at SFS2X, which is more recent and offers a ton of new features.
A feature comparison is provided here:
http://www.smartfoxserver.com/products
So it's not like Actionscript 3.
If you wish to use something like AS3 then I'd highly recommend using straight Java. AS3 is heavily "inspired" by Java. Same OOP paradigm, syntax etc... if you are familiar with AS3 moving to Java is a no brainer, plus you'll find a more rich set of API.
Back to the AS1/JS question you can import other source files using the "include" directive. You can learn all the details by taking a look at Section 7 of the SFS PRO docs: http://www.smartfoxserver.com/docs/1x/
If you haven't started developing yet, my suggestion is to also take a look at SFS2X, which is more recent and offers a ton of new features.
A feature comparison is provided here:
http://www.smartfoxserver.com/products
Re: How do you encapsulate extension logic?
Actually I tried SFS2X before Pro.
I ran into into a bunch of problems with it, and so tried Pro.
It's a shame that that javascript extensions aren't in SFS2x.
I'll probably "bite the bullet" and try to get the Java extensions working.
I find setting up Java / Eclipse, and working with Java a royal pain in the #%#. All the "overhead", importing etc etc
**** I just read / followed your excellent tutorial on setting up / compiling an extension in Eclipse, and all went smoothly (at least the compile / export process)
Thanks for the great job on writing that doc (and the rest of the docs too !
***
In contrast the AS/JS extensions have been a breeze to work with (no compiling /Eclipse etc, save / reload extension, nice extension monitoring in the PRO admin tool).
Btw is there an extension monitor in SFS2X ?
I see a 'tris' zone under the admin tool / zone config, but it doesn't show up under the zone monitor tab (just have "BasicExamples" and "BattleFarm" there)
I'm revisiting SFS2X, now.
I'll make another thread / bug report of what I'm finding
Mike
I ran into into a bunch of problems with it, and so tried Pro.
It's a shame that that javascript extensions aren't in SFS2x.
I'll probably "bite the bullet" and try to get the Java extensions working.
I find setting up Java / Eclipse, and working with Java a royal pain in the #%#. All the "overhead", importing etc etc
**** I just read / followed your excellent tutorial on setting up / compiling an extension in Eclipse, and all went smoothly (at least the compile / export process)
Thanks for the great job on writing that doc (and the rest of the docs too !
***
In contrast the AS/JS extensions have been a breeze to work with (no compiling /Eclipse etc, save / reload extension, nice extension monitoring in the PRO admin tool).
Btw is there an extension monitor in SFS2X ?
I see a 'tris' zone under the admin tool / zone config, but it doesn't show up under the zone monitor tab (just have "BasicExamples" and "BattleFarm" there)
I'm revisiting SFS2X, now.
I'll make another thread / bug report of what I'm finding
Mike
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: No registered users and 55 guests