Jump to content

AI Scripting ?


Penthouse
 Share

Recommended Posts

No, it just so happens that it's used mostly for online stuff (make sure you're not confusing javascript with java, they're completely different things), though it's perfectly suitable for other things. We chose javascript because we believe that more people will be familiar with it, and most importantly it's a much more effecient and quicker (to process) language than Lua or Python, which were our other choices.

Link to comment
Share on other sites

Don't worry, I know what Java and Javascript are are how they're different.

I think that the choice is interesting :D. JavaScript is faster? I wonder how many other people know that (or even think about using JavaScript)...

Since Javascript is commonly used online, does that mean that you could have online 'demos' of upcoming mods/stuff?

Link to comment
Share on other sites

Well, we didn't think of it either until someone suggested it in a meeting :D we ran some tests and it's 6 times faster than Lua or Python, and we definatly want a faster script language since ultimatly it'll result in faster loading times and more units on the map.

Demos? Not sure what you mean by that, but later on we'll probably have some stuff on the site that talks about modding and gives examples on how to do things.

Link to comment
Share on other sites

The javascript everyone knows and loves isn't what you will be using in 0ad. We will be using the Javascript language, but the functions you recognize like onload and such are web related and will not be in 0ad.

And Javascript isn't faster :D The language is better, but Lua was fastest. but believe me, Lua isn't something you'd want to code with :D.

Link to comment
Share on other sites

lol, hope you are not changing now ... do you have any idea how much time i spent looking for a JavaScripter? And yes, i finally got one ... and if you change language ... i will have to do it all again :D

:P

hihihi, no, just kind of kidding, i hope you dont change :D Another question ... Could you use PHP ?

Link to comment
Share on other sites

Could you use PHP ?

PHP is a server-side language that is being parsed by a webserver. I think it's absolutely unusable for any 0 A.D.-game-related things except from websites. People have been using PHP for linux scripts, though, but I don't believe it'd work well with a game.

And due to the big differences between PHP and JS, no, they won't be compliant, so you won't be able to write any 0 A.D. script in PHP.

Link to comment
Share on other sites

  • 4 weeks later...

Is there something that we AOK Scripters can play around with yet ?

(or a small AI-Faq or something like that ?)

I am sure at aiscripters.com would be alot people who would like to test and mess around a bit

Or some Game-Stats, Tech-Tree`s and such stuff ?

(i know i could search for myself - :) , but i am so lazy... :D )

great work !!!

Link to comment
Share on other sites

Ah, Berrys, good to see you again. :)

Well, since I will be developing the computer player AI, I will make sure that the scripting system will be as close to AoK ones as the programmers allow.

Instead of setting some variables, we may go the SN-mile, too, let's see. I will also write a top-notch manual on AI scripting in 0 A.D., so it won't be as hard as Javascript might suggest. :D

Link to comment
Share on other sites

Berrys, I think Javascript should be easy to understand, perhaps more so than the AoK scripting language. (I just figured out after learning Scheme in university that the AoK language is a variant of LISP). Look at a tutorial on Javascript for webpages for example. It's also very similar to PHP, C++, Java, C#, so anyone who's programmed before is likely to know it. I know many people who started programming with Javascript or PHP.

DarkAngel, I have a question about how you're using the SpiderMonkey engine. I'm planning to use Javascript in a game I'm making in Java (Mozilla also provides a Java embedding of JS). However, I'm wondering how you can implement "blocking" functions in Javascript while keeping the game single-threaded. For example, in the AI code for a unit, you might have a function like fire() or walk(x, y) which you don't want to return until the unit has completed that anmiation. Same thing might be true in a complicated trigger effect. But I don't see how you can do this if all that a user-provided JS function does is call your implementation within the same thread. Have you gotten that far with the SpiderMonkey engine? If I can't find a solution, I'll probably be forced to create my own interpreter which keeps a queue of some sort of currently waiting scripts.

One solution to my problem is to make things event-driven, so scripters can implement functions onFireComplete(), onWalkComplete(), etc. It seems very inconvenient to work with for the scripter though, for complex scripts.

Link to comment
Share on other sites

I think we're solving that by just not having any blocking operations. Most things are event-based -- e.g. using setTimeout(code, time) to execute a piece of code in some amount of time, rather than using sleep(time).

Guessing wildly (someone please correct me if I'm wrong :)) there won't even be a separate piece of script code that's executing for every unit -- a higher-level AI script will tell the unit to attack, and the unit is made to choose targets and attack them by the C++ engine. (But I wouldn't trust me to be correct about that).

It's possible to use closures in JS to emulate something vaguely like coroutines (I think that's what they're called), as a kind of cooperative threading:

function stuff(z) {
 var x = 0;
 alert("x = "+x);

 return function(){

 var y = 1;
 alert("x = "+x+", y = "+y);

 return function(){

 alert("x = "+x+", y = "+y+", z = "+z);

 }}
}

(where "return function(){" means "return now but let me be called again to continue from this point" -- a preprocessor could make it less ugly), then use it with something like

var a = stuff(5); // says "x = 0"
a=a(); // says "x = 0, y = 1"
var b = stuff(10); // says "x = 0", as an independent 'thread'
a=a(); // says "x = 0, y = 1, z = 5", accessing the original parameter to stuff()

Have the engine code store the function-object-thing that's returned, and execute it again when the blocking operation has finished, and that should vaguely work.

Alternatively, SpiderMonkey supports multiple 'contexts' which might be a simpler solution to the problem, but I don't know much about them or whether they could do what you want.

Link to comment
Share on other sites

Yes, he did. I'll probably do what he suggested, passing a "what to call next" function and an argument to the wait functions. Then I can just have a priority queue of currently waiting scripts. This should be easier to work with than general event handlers which would have to check what the object was last trying to do and then respond appropriately.

I actually just sent you a private message about the game :).

Link to comment
Share on other sites

Berrys, I think Javascript should be easy to understand, perhaps more so than the AoK scripting language.

You must be joking, the AOK method was so easy, it used very easy and logical facts.

Example:

(unit-type-count villager < villager_dark)

when someone reads this, they understand it immediately (note: i used a defconst in this fact).

If you're going to use parameters in forms of single-letters or small letters, then there will be confusion in the scripters mind, not to mention the time it will take to learn it.

I've seen my brother using JS, PHP and other methods and I can say that there are more symbols to be learned using these scripts.

Link to comment
Share on other sites

  • 6 months later...
  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...