Scripting Languages ?

Started by
45 comments, last by __ODIN__ 22 years, 1 month ago
I am using Python.

-Todd D. Degani
Advertisement
quote:Original post by __ODIN__
This sounds really dangerous, because in most cases you''ll want to have multiple scripts running concurrently. Your technique would either
a) only execute the tick of one of the scripts (freezing all the others).
or
b) Execute all scripts, snaking in and out of different scripts, and probably causing a stack-failure at the end of it..

If you only have one script running (controlling the UI, for example), the system does work, and I''ve used it before.. It''s not pretty, though..

Odin


Yeah, now that I think about it, that method wouldn''t scale well at all. With a couple dozen scripts running concurrently, jumping in and out of the game loop, things could get erratic.

Maybe a queue would work better. You could have, say, a When command that takes a condition and a series of commands:


  Character.Goto("Home")When (Character.Location == "Home") {     // Stuff to do}  


The queue would contain structs, whose members would include a condition and a script. In the above example, the script would take the condition Character.Location == "Home" and the script Stuff to do and push them to the front of the queue. Every so often, the game would test conditions in the queue, and if any are true, execute the script.

(I hope I''m not rehashing old kludges here. Since I''m likely to face these same problems in my own scripting engine, I''m curious to see other programmers'' thoughts.)
Post Extant Graphical MUD
Hey Guys,
Hangin'' out at GDC and I made the Scripting Language Roundtable (if you were there, I was the one using Simpkin *Grin*) and this was one of the questions the speaker/moderator asked. From what I can tell it seemed that a good number of people were using Java and Python. There were a few using LUA and even mention of Scheme and Small.

Of the people that were using Java and Python, about 50% of them had modified the back-end to meet their requirements.

The follow up question was why are you using an off the shelf scripting language and not writing your own. The responses to this were many and varied. Here''s the synopsis: Documentation for end users was readily available, Time and Money constraints.

There''s a follow-up roundtable on Saturday covering designing you own scripting language which should be interesting.


As for my own experience, I started off using SpiderMonkey (java-script) and quickly discovered that I did not like the method in which you expose your objects to the scripting language. I found Simpkin and have been experimenting with it for a few months. I''m almost at the point where I think that we will have to write our own scripting language... but there are always issues with this...



Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
quote:Original post by DaTroof
Maybe a queue would work better. You could have, say, a When command that takes a condition and a series of commands

Doing something like this is easy and obvious for your own scripting language - the problem is in trying to find an existing language that lets you do this cleanly. Because you need to jump out of the script at that point, and potentially execute other scripts as well as normal game code while you are waiting to jump back into that first script.



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
quote:Original post by Kylotan
Doing something like this is easy and obvious for your own scripting language - the problem is in trying to find an existing language that lets you do this cleanly. Because you need to jump out of the script at that point, and potentially execute other scripts as well as normal game code while you are waiting to jump back into that first script.


The way I pictured it, the queue would actually be part of the game engine, not the script interpreter. The "When" command would add the condition and the code to the queue. The current script would then terminate without waiting for the condition to be met. The engine, once per tick or whatever, would check the conditions in its queue. If a condition is met, the engine sends the corresponding code back to the interpreter for execution.

This would require some careful namespace management to remember local variables and stuff, but it seems cleaner than letting the original script sleep in memory, waiting for something to happen.
Post Extant Graphical MUD
quote:Original post by DaTroof
The way I pictured it, the queue would actually be part of the game engine, not the script interpreter. The "When" command would add the condition and the code to the queue. The current script would then terminate without waiting for the condition to be met.

Yeah, but what you just described requires still explicit script support for terminating a script. And going back to the subsequent code would require you to build up your symbol table again including various scopes and whatever. Which is pretty much the same as keeping it hanging around. So I don''t see the difference.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
quote:Original post by Kylotan
Yeah, but what you just described requires still explicit script support for terminating a script.


TCL supports this. When you write an extension to the language, its function''s return value determines whether the script should continue running, exit clean, or exit with an error. I haven''t tried to embed any other script interpreters (except VBScript in VB), so I don''t know what other languages can do this or how it would be done.

quote:
And going back to the subsequent code would require you to build up your symbol table again including various scopes and whatever. Which is pretty much the same as keeping it hanging around. So I don''t see the difference.


Hmm, I guess you''re right. I thought it might be easier (in terms of maintenance and debugging) to dump the script''s local variables than try to manage a hundred scripts'' scopes at once. In the end, though, you''ve still got a namespace to rebuild. Six dozen of one, half a dozen of the other.
Post Extant Graphical MUD
Most embeddable scripting languages provide facilities for you to exit the script by calling a certain function. The problem is that you then lose all your symbols as the script is considered terminated. What would be really useful is a function that suspends the script so you can resume it later. I expect there''s a language out there that does this, but I''ve not found it yet. So I think I will have to settle for my own (Flex/Bison-made) solution.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
quote:Original post by Kylotan
Most embeddable scripting languages provide facilities for you to exit the script by calling a certain function. The problem is that you then lose all your symbols as the script is considered terminated. What would be really useful is a function that suspends the script so you can resume it later. I expect there''s a language out there that does this, but I''ve not found it yet. So I think I will have to settle for my own (Flex/Bison-made) solution.


Amen! This used to bother me to no end when I was heavily into web pages and java-scripting. Sure there was SetTimeout and SetInterval, but it took a bit of figuring to use them in a more thread like manner.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
As you may have seen, I''ve been doing an article series on this subject, and although I''m not quite up to the topic of "script latency" I will eventually get to it, unless I have a freak stroke or something first.

Rolling your own can be a bit of a task, but it''s not impossible.

"Don''t be afraid to dream, for out of such fragile things come miracles."

This topic is closed to new replies.

Advertisement