Sign in to follow this  
PrincessDaisy

AngelScript over XML

Recommended Posts

I am currently working on a project that involves using scripted data. The application does not need normal scripting features (function calls, objects etc.), instead it will be used solely to hold data. So for example, and effect script would just have information relating to the script, rather than any excessive function calls...
string particleTexture   = "effect.bmp";
string particleSize      = 10.0f;
And so on... My question is, is there any advantage in using AngelScript over XML? I really like the way XML can be displayed using a standard web browser, but on the other hand AngelScript is much easier to read from the source IMO. Is AngelScript going to be substantially slower than XML, or will there be no difference? Any opinions would be welcome Thanks Daisy

Share this post


Link to post
Share on other sites
Well first of all Angelscript was not designed for this.

But I think it will do it OK, although it won't be able to have estructured data easily (trees) unless you create objects for that. I think it is perfectly possible.

And the speed depends in the way the script is structured and the xml parser you compare it with.

This topic confronts me personally cause in my project I was going to use angelscript but ended switching to XML (tinyxml)

The reason was not because angelscript had any disadvantage, the thing is that I found that the game I was trying to remake had the attribute that its objects interacted which each others to form cool systems without the need of any scripted event (what I wanted to add to it)

I decided to respect that and just have a format that reads data and focus on making more objects that could help for interactions.

Well if on my next projects I need a scripting language for my levels I would use Angelscript for sure, but for plain data I preffered XML

But it is your program so it is up to you and if you find angelscript much easier to read go ahead.


---

I think though that for the data to interact with your program it would need to be like this:


options.particleTexture = "effect.bmp";
options.particleSize = 10.0f;

And you will need an options class in your app that is linked to angelscript

Share this post


Link to post
Share on other sites
The benefit of XML here is that you can make your levels using off-the-shelf XML editing products. You'd have to code up your own editor to get this sort of thing using AngelScript (or any other script language).

I can't imagine speed will be much different with either, except that the AngelScript version could potentially be compiled into bytecode for your release version meaning you miss out the parsing step. One thing that AngelScript (or another scripting language) does have over plain XML is that you can write logic in script which is very hard or cumbersome to do in XML. I've used both scripting an XML together in my projects, meaning that scripts can be attached to the XML or loaded by them which means you get the best of both worlds.

Share this post


Link to post
Share on other sites
Quote:
Original post by Vexorian
I think though that for the data to interact with your program it would need to be like this:


options.particleTexture = "effect.bmp";
options.particleSize = 10.0f;

And you will need an options class in your app that is linked to angelscript


I wouldn't need that at all. Each script would be an individual emitter, so having all the emitter information in one script, and then that information would be read in per variable in the code (every emitter would have the same information).

So that means I wouldn't need any object orientated code.

The reason I am asking is that I have used AngelScript before, and I do like it. But if using XML (which I havn't used before) makes more sense, then I will go in that direction.

@evolutional: I can still create my normal text editor program to create the scripts in the same way I would create the XML versions to.

Daisy

Share this post


Link to post
Share on other sites
Quote:
Original post by Vexorian
I am saying it would have been much easier to access the members of a class that is on your app than browsing for all the variables in the stack and checking their names and values


That is true, but this is not the only way in which I will use it, and I want to keep a constistant interface.

When I come to localise my game, I will have all the strings in a script. Now I cant have an object in this situation, as I will no tknow how many strings I will have, or what their variable names are. If I am to use AngelScript, I will have a hugh list of strings, their ID, and the string they relate to.

In this case, AngelScript is much easier to read, and use (IMO), but slow?

Daisy

Share this post


Link to post
Share on other sites
Well, in my opinion AngelScript is not the way to go if you only need to store a lot of data. I did not design the library with this in mind, and do not think I will take it in that direction in the future either.

I'm a big fan of XML myself, and in my upcoming game project I intend to use XML for data and AngelScript for scripting.

If you want a consistent interface for both data and scripting then perhaps Lua would be what you're looking for. I do not have any personal experience with Lua however so I cannot say if this is true or not.

You mentioned that you'll make your game localizable and that you will store all the strings in the script, whether it be AngelScript or XML. May I suggest a simple text file instead. Your application would then read this text file and with an extremely simple parser store each of the strings in an internal structure. This would simplify both the file format and the application's interface for the scripts.

comparisons:

AngelScript

string str1 = "Hello";
string str2 = "Andreas";


XML

<strings>
<str id="1">Hello</str>
<str id="2">Andreas</str>
</strings>


Text file

1:Hello
2:Andreas


Which do you think is easiest to edit? Which would be easiest to load and access from the application?

Regards,
Andreas

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
If you want a consistent interface for both data and scripting then perhaps Lua would be what you're looking for. I do not have any personal experience with Lua however so I cannot say if this is true or not.


I'm not agree with this.
Xml can store both data and AS scripting. I've done it this way !

The Datas are stored in a normal XML way and Scripting is included through XML comment.

AbrKen.

Edit : Oops, the GD is deleting the XML comment !

Edit2 : After having VBScripting error I have removed the xml sample.

Share this post


Link to post
Share on other sites
That sounds like a good idea. But I have one doubt:

Can the XML comments include XML special characters like < > & " etc? Or do you have to escape them?

It probably can, since you're doing it like this.

By the way, to show XML examples you'll have to escape the characters that interfere with GameDev.net's HTML tags.

Regards,
Andreas

Share this post


Link to post
Share on other sites

Quote:
Original post by WitchLord
That sounds like a good idea. But I have one doubt:

Can the XML comments include XML special characters like < > & " etc? Or do you have to escape them?


You'd use CDATA sections in the XML to contain your script, this essentially tells the XML parser to 'switch off' parsing until the end of the CDATA section.

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
Can the XML comments include XML special characters like < > & " etc? Or do you have to escape them?



In comments, the only thing that isn't allowed is -- and even that is only for compatibilty (probably with sgml). --> ends the comment, so your comments obviosuly can't contain that either

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
Can the XML comments include XML special characters like < > & " etc? Or do you have to escape them?


Quote:
Original post by evolutional
You'd use CDATA sections in the XML to contain your script, this essentially tells the XML parser to 'switch off' parsing until the end of the CDATA section.


The XML parser is an inhouse one. It allows < or > or even -- in comments.
It just scan for "-->" for getting the end comment.

First I wanted to implement the code in a CDATA section (as quasar3d has suggested) but our inhouse XML parser would have too been too many modified, and as I'm a little lazzy, the comments jusst has done the trick !

So I'm trying to insert a sample ...


<XPNTree>
<CUSTOM>
<version>1</version>
<author>abrken</author>
</CUSTOM>
<COMMON>
<CODE Name="thefunc" Pure="1"><!--// -------------------------
// Global Function : thefunc
// -------------------------
int thefunc()
{
return i--;
}
--></CODE>
<CODE Name="GLOBAL" Pure="1"><!--// ------------------------
// Global Function : GLOBAL
// ------------------------
int i = 0;--></CODE>
</COMMON>
<PAGE Default="1" File="Animation.xml" Name="page1">
<TIMEOUT Elapse="1">
<NAV Name="page2"/>
</TIMEOUT>
<OnBeforeStart><!--// ----------------------------------------
// page1 : 2) Avant Démarrage Visualisation
// ----------------------------------------
--></OnBeforeStart>
<MOUSE>
<CIRC Coord="0351,0220,0146,0393">
<EXEC><!--// Add Your AngelScript
CString csFichier;
Presenter.FileDialog(true, "Selection fichier", "*.txt", "", "Fichiers Text (*.txt)|*.txt||", 0, csFichier);--></EXEC>
</CIRC>
</MOUSE>
</PAGE>
<PAGE File="Animation.xml" Name="page2">
<TIMEOUT Elapse="1">
<NAV Name="page1"/>
</TIMEOUT>
<OnBeforeStart><!--// ----------------------------------------
// page2 : 2) Avant Démarrage Visualisation
// ----------------------------------------
--></OnBeforeStart>
</PAGE>
</XPNTree>

Share this post


Link to post
Share on other sites
You've given me some good suggestions that I think I'll be using myself when I get that far in my game project. I wasn't aware of the CDATA section before evolutional mentioned it, but this would be the perfect solution. Now I know what to answer when others ask about how to combine XML and scripting. [smile]

For everyone's information, here's an example of a CDATA section (from W3Schools.com):


<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1
}
else
{
return 0
}
}
]]>
</script>





Doing it the way abrken does it also work, though I'd prefer using the CDATA section as that is part of the XML standard so that common XML editors can be used without problems to edit your scripts.

Share this post


Link to post
Share on other sites
About editing, rather you choose CDATA (that is best appropriate) or XML comment, the result is an xml file that will be easely edited with some xml editor, but ... none of them will understand your script. you'll then have to "compile" the xml file and check for errors and so.

The better is to write your own editor.

If you do not take time to write an editor you will endup loosing your time in xml editing/application compiling and finally, all of the time in addition would have been the time to write your own editor.

This is just my point of view taken from a real project ;)

Regards,

AbrKen.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this