May 23, 2012, 11:59:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: "Include" directive - How to use it? I don?t remember.  (Read 763 times)
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« on: August 19, 2008, 08:03:50 PM »

I want to use a "include" in a .gsl to include the contents of other .gsl file.

How do I type it? I don?t remember.
And other question:
Can I use something like:

"From XXXX import XXXXX" as in python so that I can import only a specific struct or function to the file?



Thanks in advance.
Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #1 on: August 20, 2008, 06:11:49 AM »

hm, i cant find any INCLUDE in the old templates, the only thing i find is:

ControllerType Scripted
ControllerSetting ScriptFile ../../../scripts/controllers/character.gsl

That you have in the character.opr
Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #2 on: August 20, 2008, 10:01:27 AM »

I copied this from a old BV thread:

http://64.233.167.104/search?q=cache:0MKh91jpGZ8J:www.beyondvirtual.com/smf/index.php%3Ftopic%3D1535.0+INCLUDE+site:beyondvirtual.com&hl=en&ct=clnk&cd=1&gl=us
-------------------------

i wouldn't use includes to copy any of the default controller functions out into seperate files - it's more for external functions that you might call from your game.  not sure how it would behave if the primary controller functions are called from outside...

otherwise, the syntax is as follows:


Code:
#include "..\scripts\utils.gsl"


the include directive can ONLY be used at the top of a script file - it MUST be the first command lines of the script file (not counting any comments).  The preparser looks for include directives and then basically builds a complete script file from the various pieces and then runs it through the compiler, much like a standard compiler does (ie c/c++).
Logged
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« Reply #3 on: August 20, 2008, 10:53:06 AM »

Many Thanks!

Quote
t's more for external functions that you might call from your game.  not sure how it would behave if the primary controller functions are called from outside...

Yes, it is exactly for this I want it. To make a library of my utility functions without having to put them on every .controller script.


Cheers.
Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
gekido
Guest
« Reply #4 on: August 25, 2008, 03:53:50 PM »

Quote
the include directive can ONLY be used at the top of a script file - it MUST be the first command lines of the script file (not counting any comments).  The preparser looks for include directives and then basically builds a complete script file from the various pieces and then runs it through the compiler, much like a standard compiler does (ie c/c++).

We've made it a bit more forgiving now - but it's still a good idea to do all of your includes at the top of the script file.
Logged
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« Reply #5 on: August 26, 2008, 10:34:28 PM »

Thanks for the info. How forgiving exactly? Not having to add those lines of comments at the end of the scripting? Or are you talking about use of memory etc?

Ah, it?s working here. Thanks again, Ron.

I think it?s a very useful feature. I would recommend newbie scripter dudes to add this to your "arsenal" of workflow. At least in my opinion it?s a nice way to organize the general utility functions and variables and at the same time "modularize" some stuff. Like I can some libraries in gsl files (with variables and functions) like:

combatSystem.gsl

advancedCameraSystem.gsl

collisionCallbacksSystem.gsl

advancedViewportFXSystem.gsl

The main thing here being the fact that I don?t need to implement in each controller file the code for things I?ll use (and data I?ll need) for many controllers.
 Smiley

Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #6 on: August 26, 2008, 10:45:55 PM »

Ah, it?s working here. Thanks again, Ron.

That wasn't me, I wish I knew scripting that well  Grin Everything in my post was what I copied from the archive of the BV forum. Anyways, glad its helping.
Logged
grubert
Full Member
***
Posts: 183


Everybody is very nice, but my jacket disappeared.


View Profile WWW
« Reply #7 on: August 26, 2008, 11:05:44 PM »

Thanks anyway for the link. Smiley

Just a warning for those newbies going to try to use include:

if a variable, function, struct etc, in a .gsl linked with #include has the same name of another variable or function etc etc in another linked file, they will conflict, the game won?t run and will spit you an error message.
You have to be paying attention to the names in those included files so that they don?t repeat.

But I think this is easy. You can, for example, prefix your functions with a short and meaningful name. Like if you have a library of functions and variables for combat in a file named

combatSystem.gsl

you can prefix a variable for "force" with "comb". So instead of

Code:
int force = 10;

you declare

Code:
int combForce = 10;

or with an underline to separate, like

Code:
int comb_Force = 10;


« Last Edit: August 26, 2008, 11:09:53 PM by grubert » Logged

my portfolio and weekly posting:
http://athossampaio.blogspot.com
gekido
Guest
« Reply #8 on: August 29, 2008, 06:30:40 PM »

Yeah this is unfortunately a side-effect of not having proper classes in angelscript (something that we're looking to address in the near future), but can be worked around with proper naming conventions.

Probably the best way to handle this kind of include system is to treat everything like a class method / variable even if it isn't, like so:

script file: myClass.gsl
Code:

bool myClass_Variable = false;

void myClass_FunctionName()
{
}

This way with a single look you can instantly tell what 'class' (ie include) the variable and function belong to.


Logged
Pages: [1]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!