|
|
| A Scripting Language. |
|
Paul Pridham
Member #250
April 2000
|
Quote: I've yet to see a scripting system that will actually re-load the script in the middle of using it. I don't really see what the problem is, especially if each object has its own scripting system instance. - Close the object's script If multiple objects share the same scripting system instance, then provide an interface for accessing that instance and do everything under the hood. Have the script-reload post a message to all objects using the particular script instance to reset themselves and re-link. ---- |
|
curtis warren
Member #3,898
September 2003
|
Wouldn't it make more sense and be less of a hasle to just go back to the main menu, change the script, then start again? Although, changing it while it's running shouldn't be too hard, either. |
|
Korval
Member #1,538
September 2001
|
Quote: - Close the object's script Which is not the same as reloading the script while using it. The state information is lost. As such, if it's an AI script that's doing something odd, you can't just reload the script in the middle, as the state information could be responsible for the oddity. |
|
Marcello
Member #1,860
January 2002
|
So anyway, I'm trying to compile this spidermonkey thing and it's designed for msvc++, though it does compile on unix/gcc and mac... I could compile the dll in msvc++, but I'd rather work on the game itself in mingw. Any ideas as to how to get that working in mingw (supposedly the entire mozilla tree can be compiled in mingw since v1.4b, not all features supporting, but I'd assume javascript is a critical part (considering the entire interface is coded in it)). Here's an interesting link: projects using js engines Couple game-related projects there. Thanks, Marcello |
|
Korval
Member #1,538
September 2001
|
Quote: Here's an interesting link: projects using js engines Couple game-related projects there. Yes. And people have written raytracers in PostScript, of all things. That doesn't mean that it's a good idea. Not that I'm saying that JavaScript is unreasonable for a game; I've never used it. But it was designed for something wildly different from games, or even being embedded in C/C++ programs, unlike Python or Lua. |
|
Peter Hull
Member #1,136
March 2001
|
Quote: I've yet to see a scripting system that will actually re-load the script in the middle of using it. I believe if you try this in Lua it should just work. (i.e. call lua_dofile again) Even if you do this in the middle of a lua method it will just rebind the method's name to a new instance, and the old one will eventually get garbage-collected. Any comments, Korval? Pete |
|
spellcaster
Member #1,493
September 2001
|
Quote: But it was designed for something wildly different from games, or even being embedded in C/C++ programs, unlike Python or Lua.
it was defined as a scripting language. That's why there's a "script" even in the language name. And if you can create neat games using JavaScript in a browser, just imagine what could be done if that javascript has access to game specific native classes. -- |
|
Peter Hull
Member #1,136
March 2001
|
Here's a link from the game developer's conference next year - there's going to be session devoted to Lua. Pete |
|
Paul Pridham
Member #250
April 2000
|
Quote: Which is not the same as reloading the script while using it. The state information is lost. As such, if it's an AI script that's doing something odd, you can't just reload the script in the middle, as the state information could be responsible for the oddity. If the state information is stored in the object and not the script, this is not an issue; the object can keep its original state. If the state information is stored in the script, the state's details can be saved, and then restored after the script is loaded. It isn't a problem that's unsolvable, it just takes the proper logic to do what you want it to do... just like any programming problem. ---- |
|
Korval
Member #1,538
September 2001
|
Quote: I believe if you try this in Lua it should just work. (i.e. call lua_dofile again) Even if you do this in the middle of a lua method it will just rebind the method's name to a new instance, and the old one will eventually get garbage-collected. I don't think that will necessarily work. At least, not for the way that I use Lua. What I prefer to do is have each Lua script file represent a class (thanks to LuaBind), with an exposed global function that generates instances of that class. Which means that Ai scripts are actual instances of the pure-virtual AIObject base class, for example. A LuaBind class is built out of a table of functions. Even if you change the file implementing the class, instances that have already been created will still point to the old methods. Quote: it was defined as a scripting language. That's why there's a "script" even in the language name. PostScript has "script" in it's name. That doesn't make it an appropriate language for writing ray-tracers or non-printer code, even if it can be done. Just because you can do a thing in a language doesn't mean that it is the appropriate use of that language. Quote: And I'm pretty sure that there're more games written in JavaScript than games written by you in c/c++. God, it was really nice not having you around. Quote: I also think that most browser are written in C/C++, so it was designed to be embedded in C/C++ programs. Most printer drivers are written in C/C++, too. That doesn't make PostScript embedded. A scripting language is considered to be "embedded" in another language if the server language can expose an arbitrary API to the script language. Normal JavaScript doesn't have this facility, but both Lua and Python do. Quote: If the state information is stored in the object and not the script, this is not an issue; the object can keep its original state. If the state information is stored in the script, the state's details can be saved, and then restored after the script is loaded. It isn't a problem that's unsolvable, it just takes the proper logic to do what you want it to do... just like any programming problem. I admit that it is possible to have hot-swapping of scripts. However, it isn't a trivial exercise, nor does it just come with any particular scripting language (unless you write one with that in mind. Which is doable, and might be a laudable goal for a scripting system). You have to do work at it to make it happen. Granted, C/C++ can't do it at all, even with .dll's. |
|
23yrold3yrold
Member #1,134
March 2001
|
Korval (to Spellcaster) said: God, it was really nice not having you around. Was that necessary? >_< -- |
|
spellcaster
Member #1,493
September 2001
|
Quote: God, it was really nice not having you around. My whole point is that you said that JavaScript can't be used to code games. Which is wrong. And the funny thing is, that you can't argue about that, since there're enough games which were coded in JavaScript. Quote: Most printer drivers are written in C/C++, too. That doesn't make PostScript embedded. I must admit, that I have problems following you here. I guess the idea is that since both "JavaScript" and "PostScript" have "script" in their name, and postscript is not intended to be used as an embedded language, JavaScript can't be used as an embedded language as well? Quote: A scripting language is considered to be "embedded" in another language if the server language can expose an arbitrary API to the script language. Agreed. Of course it's not the server language, but the server that's exposiong an API which can then be used inside a script. Quote: Normal JavaScript doesn't have this facility, but both Lua and Python do.
Um... of course not, since the (to use your words) the "server" is exposing the API. Quote: but both Lua and Python do.
Wow. That's news to me. BTW, the way of using LUA as an embedded language in your own programm is almost exactly the same as using SpiderMonkey To make a long story short: You can easily use javaScript for games, and there's nothing wrong with that. JavaScript is an embedded Scripting Language. In fact, it was desiged to be an extension language. And even in an environment not specific to games (web browsers), you can use it to code great games. Now imagine what you can do with it if you embed it in a game specific environment. -- |
|
Marcello
Member #1,860
January 2002
|
Ok, arguing is all very fine and well, but does anyone have an answer to my second question about how I actually can use spidermonkey? Marcello |
|
spellcaster
Member #1,493
September 2001
|
I just downloaded the spider monkey source. First of all, you have to define Then I changed jstypes.h to make sure the gcc int64 version is used even if win32 is defined: #elif defined(WIN32) typedef long long int JSInt64; typedef unsigned long long int JSUint64; In jslibmath.h change #if defined(_WIN32) && !defined(__MWERKS__) #define JS_USE_FDLIBM_MATH 1 to #if defined(_WIN32) && !defined(__MWERKS__) #define JS_USE_FDLIBM_MATH 0 Then I got an error like this: D:/GameProgramming/JavaScript/spidermonkey/prmjtime.c:429: undefined reference to `JSLL_Zero' Which was fixed by replacing JSLL_Zero with 0. Then it compiled without any errors... [edit] static JSInt64 ll_zero = 0x0000000000000000LL; static JSInt64 ll_maxint = 0x7fffffffffffffffLL; static JSInt64 ll_minint = 0x8000000000000000LL;
-- |
|
Marcello
Member #1,860
January 2002
|
Quote: Then it compiled without any errors... Forgive me if this sounds ungrateful, but how exactly do I 'compile'? I looked through the readme, and tried: nmake -f js.mak (builds the vc++ version), make -f Makefile.ref, gives me the following: sed: -e expression #1, char 2: Unterminated address regex cat: ../../dist/WINNT4.0_DBG.OBJ/nspr/Version: No such file or directory d was unexpected at this time. make: *** [all] Error 255
But mainly I haven't a clue what I'm doing. Marcello |
|
spellcaster
Member #1,493
September 2001
|
Quote: Forgive me if this sounds ungrateful, but how exactly do I 'compile'?
Take the .c files in the directory and feed them into a compiler. I'm using this makefile, which was generated by slickedit after I told it to use all files (but js.c - since this file is a demo).
-- |
|
Korval
Member #1,538
September 2001
|
Quote: Was that necessary? >_< I found his tone to be unnecessarily condescending. <quote>My whole point is that you said that JavaScript can't be used to code games. Which is wrong. And the funny thing is, that you can't argue about that, since there're enough games which were coded in JavaScript.quote] But I didn't say that. Indeed, I pointed out that PostScript could be used for very non-printer-related tasks a number of times. My point was that just because you can use a hammer to screw in a nail doesn't mean that you ought to. And just because others do something doesn't mean that it's a good idea. Quote: I must admit, that I have problems following you here. I guess the idea is that since both "JavaScript" and "PostScript" have "script" in their name, and postscript is not intended to be used as an embedded language, JavaScript can't be used as an embedded language as well? No, I was simply refuting your assertion that the fact that JavaScript had script in the name meant that it was intended as an embedded language. You did say, "That's why there's a "script" even in the language name," thus suggesting that the fact that it had "script" in the name was meaningful in terms of it being an embedded language. Quote: Um... of course not, since the (to use your words) the "server" is exposing the API. Not an "arbitrary" API. It exposes a particular one, but if it can't expose arbitrary one, then the scripting language cannot grow and change. It can't be used for an arbitrary purpose without having to build it all in JavaScript. I understand that there is a way to run JavaScript using new API functions. But, it was not designed with that in mind originally. And I would imagine that this more recent addition probably isn't that well integrated into the rest of the language, much like making classes in Lua was difficult (until LuaBibd just did it for you). Granted, I could be wrong, but it certainly stands as a possibility. Quote: Last time I had to write wrapper functions in C and register these functions to LUA. Use LuaBind. It's GoodStuff(tm). It writes them using template metaprogramming/magic. It's a bit strange to look at, as I can't see how some of it is valid C++. BTW, technically, you don't have to use wrappers at all. All you need to do is have your C/C++ code use the Lua stack for function calls Not that this would be a good idea. Indeed, it probably ranks up there with using PostScript for raytracers. Or maybe JavaScript for games |
|
spellcaster
Member #1,493
September 2001
|
Quote: No, I was simply refuting your assertion that the fact that JavaScript had script in the name meant that it was intended as an embedded language.
But the script in JavaScript is used to show it's a embedded language. Quote: You did say, "That's why there's a "script" even in the language name," thus suggesting that the fact that it had "script" in the name was meaningful in terms of it being an embedded language. Sorry. What I meant was "They even put a script in the name to show it's a scripting language". Quote: understand that there is a way to run JavaScript using new API functions.
Korval, the API used to access the server is not implemented in the scripting language. Not is is exposed by it. You can't expose an API using LUA. You can create wrapper functions using LuaBind, but this doesn't produce "pure Lua" code. Quote: But, it was not designed with that in mind originally. And I would imagine that this more recent addition probably isn't that well integrated into the rest of the language, much like making classes in Lua was difficult (until LuaBibd just did it for you). Granted, I could be wrong, but it certainly stands as a possibility.
Korval, there's no need to "add something" to JavaScript. You're not changing the language. All you do is to expose some new objects and or functions to it. Quote: BTW, technically, you don't have to use wrappers at all. All you need to do is have your C/C++ code use the Lua stack for function calls
And still it would be the server that's doing the work. Which makes sense If you compare the way the integration with C/C++ is handled in Lua, Python and Javascript, you'll realize that it's almost the same. Don't try to insist that JavaScript isn't a good choice. Try to keep an open mind. I have the impression that you still link "javascript" with WebBrowser because that was the first application using JavaScript as an embedded language. Quote: Not that this would be a good idea. Indeed, it probably ranks up there with using PostScript for raytracers. Or maybe JavaScript for games
Hm... I think using JavaScript for games is better then talking garbage about PostScript raytracers But before we get down to that level again, could you please give me 1 reason why JavaScript should not be used as an embedded language for games? -- |
|
nonnus29
Member #2,606
August 2002
|
Not too intrude on the discussion of titans here; but javascript specifically has come along way from just scripting webpages; it even has a standard - http://www.ecma-international.org/publications/standards/ECMA-262.HTM Javascript is an integral part of the Mozilla browser project: Quote: As it is widely used in Mozilla, it makes sense to explain how JavaScript and C++ relate to each other in the Mozilla source code. C++ is a compiled language, while JavaScript is an interpreted language. JavaScript is most commonly known as a technology used to implement web sites. However, the developers of Mozilla decided that the Mozilla source code itself should consist of a mixture of both languages. Using Spidermonkey is much like using Lua in that the api gives you a stack to pass values back and forthe to the interpreter. |
|
Korval
Member #1,538
September 2001
|
Quote: I think using JavaScript for games is better then talking garbage about PostScript raytracers It isn't garbage; it's the truth. That code exists out there somewhere, as strange as it may sound. Quote: But before we get down to that level again, could you please give me 1 reason why JavaScript should not be used as an embedded language for games? Because it wasn't designed for use as a general-purpose embedded language. It is a web browser language that was eventually extended with the ability to be used in more applications. Lua and Python are designed with general purpose programming in mind. Lua, for example, was built for speed. Can the same be said for JavaScript? I think the better question, considering that there are two other, quite viable, alternatives, can you give me a reason to use JavaScript for non-web browswer tasks? |
|
23yrold3yrold
Member #1,134
March 2001
|
I know there's a JavaScript raytracer ... -- |
|
spellcaster
Member #1,493
September 2001
|
Quote: Because it wasn't designed for use as a general-purpose embedded language. Please tell me, what feature you need is missing? Quote: t is a web browser language that was eventually extended with the ability to be used in more applications. Not true. Quote: Lua, for example, was built for speed. Can the same be said for JavaScript? While JS was certainly not built to be the fastest kid on the block, it is pretty fast. Quote: I think the better question, considering that there are two other, quite viable, alternatives, can you give me a reason to use JavaScript for non-web browswer tasks? This is not the point here, but I'll give you some reasons later on. First I'd like to notice that "because other solutions are around" is not a very strong point. That's why there're quite a few languages besides C. Ok, now that we have agreed on that there is no technical reason not to use Javascript as a scripting language for games, we come down to taste. Why would somebody want to use JavaScript for games? The obvious reason is "because you can". On allegro.cc are at least 3 people at the moment using a javascript engine. And if you consider the small amount here actually interested in scripting , that's not bad at all. But why do they want to use it? Why not Lua? JavaScript is a powerful language. It's object oriented but is also great for procedural jobs. So the language itself is easy to use and offers lots of features. Easy to learn It really is Debugger support That's an important point for me. Number of users JavaScript has a high user base. If I use JS as a scripting language I've a lot of people who could design levels. Scripting system is easy to set up I downloaded SpiderMonkey when Marcello asked for help. And now I've a running scripting system. Neat. Contexts I can execute scripts in different contexts but need just one runtime. Security I can run scripts with different security levels easily. For me "powerful language" and "number of users" was the key. I was toying around with the idea of using javascript for some time, but after I realized how easy it is to set up (which is the 3rd point) I'll be using it from this point forward. I want to close with: Quote: can you give me a reason to use JavaScript for non-web browswer tasks? I gave you several above. Can you give me one reason not to use it? -- |
|
Peter Hull
Member #1,136
March 2001
|
|
spellcaster
Member #1,493
September 2001
|
The js lib has around 550kb on my system. I'm not sure if I can reduce that (I didn't really look at the source, I just compiled it). But I guess you can get a smaller executable if you include only the unicode or non-unicode version of the string functions. But yes, liblua is smaller. -- |
|
CGamesPlay
Member #2,559
July 2002
|
Another language that I found to be very nice was C-Smile. It is more like java, but has certain traits of javascript. -- Ryan Patterson - <http://cgamesplay.com/> |
|
|
|