• 15
• 15
• 11
• 9
• 10

# Building Part of a Script

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

## Recommended Posts

Hello all, Is it possible to build a specific function and only that function in a script? I will explain by example: Suppose I have the following script in a file called greeting.as:
void sayHello()
{
print('Hello!");
}

void sayGoodbye()
{
print("Goodbye!");
}

Normally I would get the contents of the file, and call AddScriptSection. However when I call Build, It compiles both functions. Is there anyway to have both functions in the same file and only build the sayGoodbye function and not the sayHello function? One way is to parse out the function I want, but this can get complicated. Maybe the ability to specify what specific function to build when calling Build would be a nice addition to AngelScript or better yet, specify a specific function in AddScriptSection? If not, any help as to how to do it would be greatly appreciated. Sonicphreak

##### Share on other sites
The simplest way would be to have multiple files. The problem with only building specific functions is that it might call functions you just told it not to compile. Furthermore, it still must know about all the functions in the file to do proper function overload resolution.

##### Share on other sites
Hello,

I thought about the function dependancies, but the function overloading is something I didn't consider. But what if I were really careful? I really just wanted to do this for organization purposes. Oh well, thanks for the quick response none the less.

Sonicphreak

##### Share on other sites
Are you sure that you are not over organizing?

##### Share on other sites
Ha ha! Possibly. But that is like me. I will stick with multiple files. And by the way, great work Witchlord and all other contributors. Keep up it up!

##### Share on other sites
Just go XML.

Define one function per xml node and parse the desired node.

Of course you'll get into problems when you'll have to re-compile a previously compiled function because AS will claim that the function was already defined.

I don't know about AS 2.x but what I'm doing in 1.10 is on each compile request, I build a new ScriptEngine (with registrering the prog objects), compile the desired script function and get the result to be shown, then destruct the engine.

AbrKen.

##### Share on other sites
You definitely need to use separate script sections if you want to control which functions to compile. AngelScript already does everything you need to get this to work, as you can add multiple sections to the same module before building it, or even have multiple modules communicating with each other through function binding.

If you don't want to use multiple files for the functions, you'll need some way of separating the functions, in which case I'd prefer XML files, like abrken suggested, but you could also use a simple separator, i.e. a token that doesn't appear anywhere else in the script file.

In AngelScript 2.x it is no longer necessary to destroy the engine between compiling the scripts. A module can be discarded and recompiled without affecting the other modules. In 2.4.1 it is even possible to change the engine configuration without recompiling unaffected script modules.

Regards,
Andreas