• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Scripting Languages ?

## 46 posts in this topic

you don''t have to triple-post
0

##### Share on other sites
I''m not using any scripting engine, as such. I wrote a very basic system myself that accommodates if/else blocks, and sleeping for a period of time. But there''s no real variable support, no scoping, no switch/case, no for loops, no whiles or repeat loops, etc.

Each script that runs allocates a new Context object. This is where the current line number and variables are stored. If it needs to sleep for a while, it stops executing but keeps hold of the Context object. When I wake it up, it continues from where it left off by continuing to use that Context object, and frees it when it terminates. There have to be lots of checks in the system as it''s possible that the targets of the variables could become invalid while a script is sleeping.

In the future I might try some sort of Flex/Bison thing, but I will have to see how easily I can incorporate the sleeping/yielding into that.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
0

##### Share on other sites
quote:
Original post by __ODIN__

I''m sorry if I didn''t get the point across. In most cases, the game needs to run multiple concurrent scripts, with the ability to "step out of" the script while executing long-running C functions (Essentially allowing the rest of the program, such as the renderer and the tick loops to run).

I can think of one possible solution. Let''s say you have a GameLoop function that updates ticks, renders, etc. You could write an extension to your scripting language that calls the GameLoop function. Here, I''ll call it DoEvents, since it''s similar to DoEvents in VB:

  Character.Goto("Home")Do Until (Character.Location == "Home") {    DoEvents}// etc.

Thus, the GameLoop would still be executed while the script waits for the character to get home.

One obvious danger of this method: what if a second script gets triggered for the same character while the first one is still running? If so, you need to determine whether the first script should die or the second should get cancelled. Adding a counter to the Do loop might be a good idea, too, so if the guy doesn''t get home after a few minutes, he quits trying.

Anyway, I just thought I''d throw that idea out there. I suspect it would be a bear to implement, but any solution to this problem is likely to be non-trivial.
0

##### Share on other sites
So far all the tutorials I have seen are really crummy!

I made my own, its an interpreted bytecode, and changes the game by passing paramiters through external functions using ''registers''

Each class can run one script synchronosly (so no waste time loops, only timers). There is also a class to tie them all together and support the external interface and timers

I made the assembler and dissasembler in VB too
0

##### Share on other sites
I can think of one possible solution. Let''s say you have a GameLoop function that updates ticks, renders, etc. You could write an extension to your scripting language that calls the GameLoop function. Here, I''ll call it DoEvents, since it''s similar to DoEvents in VB:

Thus, the GameLoop would still be executed while the script waits for the character to get home.

One obvious danger of this method: what if a second script gets triggered for the same character while the first one is still running? If so, you need to determine whether the first script should die or the second should get cancelled. Adding a counter to the Do loop might be a good idea, too, so if the guy doesn''t get home after a few minutes, he quits trying.

[/QUOTE]

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
0

##### Share on other sites
I am using Python.

-Todd D. Degani
0

##### Share on other sites
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.)
0

##### Share on other sites
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
0

##### Share on other sites
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 ]
0

##### Share on other sites
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.
0

##### Share on other sites
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 ]
0

##### Share on other sites
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.
0

##### Share on other sites
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 ]
0

##### Share on other sites
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.
0

##### Share on other sites
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."
0

##### Share on other sites
quote:
Original post by Redleaf
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.

Yes, I read the first two quite attentively and skimmed the 3rd one. I thought you gave the subject a great treatment. What do you have planned for the 4th installment? How many installments do you have planned? Do you have a plan? - or a rough plan more or less that can be adapted to meet requests and such?

Here, let me give you a plug: Creating a Scripting System in C++ Part III: Dynamic Loading

0

##### Share on other sites
I have a basic "overview" if you wouldn''t go so far as to call it a plan. I outlined it in the first article. What I''m doing is taking a few related parts of the complete system, and implementing them a little at a time to see how much explanation and code changes they require. Using that, I gauge how much I can reasonably fit into a single article without it becoming bloated.

The current part I''m writing deals with a data stack and implementing program flow. It make use of a few basic concepts that can be used to develop many of the common features of high-level languages, such as complex mathematical expressions and control structures such as if-else and looping.

I originally was expecting at least 7 or 8 parts, but with the way I''m going, it may actually take more. I''d rather have the series be longer than not do justice to a particular topic.

And of course I''m also trying to meet requests that are made as best I can.

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

##### Share on other sites
Cool. So are you aiming for a particular publishing rate - like once or twice a month or are you going to take it slower than that - and for that matter do you have much say in that at all? - that is, that''s a perogative of the gamedev editors?
0

##### Share on other sites
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.

Again, you might want to look into TCL. It lets you create a namespace and execute a script in the namespace''s scope. Variables created in the namespace aren''t lost when the script terminates. I don''t know if this is exactly the implementation you want, but it sounds to me like it would do the job.

http://www.scriptics.com/man/tcl8.4/TclCmd/namespace.htm has some good info, particularly in the "What is a namespace?" section halfway down the page.
0

##### Share on other sites
Actually, I just work on the current article whenever I have the free time to do so. I don''t physically put the articles up myself, so the true perogative of when they will be featured is left to Dave, as long as I''ve submitted the next article. When my free time is lacking, the rate at which I will get the articles submitted suffers, unfortunately.

But once an article is submitted, Dave normally has it up within a week.

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

##### Share on other sites
TCL''s namespaces look more like a hack that gets around the problem rather than a clean solution. (Relative to the problem, that is - I''m sure they are an elegant solution to other issues.) Does it support restarting a script half-way through?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
0

##### Share on other sites
quote:
Original post by Kylotan
TCL''s namespaces look more like a hack that gets around the problem rather than a clean solution. (Relative to the problem, that is - I''m sure they are an elegant solution to other issues.) Does it support restarting a script half-way through?

Admittedly, this solution is probably beyond the original intention of namespaces. The language itself doesn''t support restarting scripts, but it can be simulated through an extension. You''d have to pass the code within my theoretical When command back to the interpreter extension (the When command''s code) as a string argument, store the string in the engine''s queue, and pass it back to the interpreter when the condition is met, executing it in the script''s original namespace so previously declared variables don''t get lost. When the script is terminated, we can clear the namespace. This would solve the problems we discussed about maintaining scope and passing control back to the engine itself.

Doesn''t sound very elegant, does it? It may not be; I haven''t actually tried to implement it. Also, it negates the possibility of precompiling scripts, since the engine is being forced to treat code as data. I''m at a loss for a better solution, though.

I won''t beat this dead horse any longer, but if you have any other thoughts, I''d love to hear them. It''s been an interesting discussion.

0