# Unity What I want in a language

## Recommended Posts

Hello! I've been working on a 2D tile-based RPG engine that uses my own scripting language but I've decided that I want to abandon this clumsy, informal language of mine and utilize a 3rd party embeddable scripting language. I've looked at a few possibilities (Lua, in particular) but it's not clear to me how or if these languages are really meant for what I want to do. Here's how my engine has worked so far: - C++ provides a library of general functions that control the game environment: creating characters, moving characters, and other fundamental arbitrary actions. - C++ creates multiple instances of what I've called ScriptHandlers. These objects have an associated script file. - Every frame, C++ loops through the ScriptHandlers. Each SH takes this opportunity to run part or all of its script. These scripts will call C++ functions to supply game-specific activity (creating a particular character, moving a character, displaying some dialogue, etc). There may be logic if/then) and looping involved. At some point, the script may need to halt itself. The program flow returns to the SH; the scripting language does not just call another C++ function! - The next time a particular SH has its turn to run its script, it needs to restart wherever it left off. There are basically three levels of "game control" going on here: Graphics, user input, collision detection, etc (C++) -> Game logic (script) -> -> Actual creation/manipulation of characters, dialogue, etc (C++) The big issue here is that the scripts need to be able to halt their own execution (and control returns to C++), but save their place so that C++ can restart the script where it was left off. Perhaps a virtual machine that can be paused and resumed. I know I've made a few threads on this subject already, but I've found few resources on these languages, unfortunately, so it's difficult to make an educated guess at what's appropriate for me. I appreciate any advice what-so-ever. Thanks!!

##### Share on other sites
Quote:
 The big issue here is that the scripts need to be able to halt their own execution (and control returns to C++), but save their place so that C++ can restart the script where it was left off. Perhaps a virtual machine that can be paused and resumed.
You want continuations, it seems, to implement cooperative multitasking.

Or (if they just need to be halted and resumed once) generators.

Any language which provides closures or explicit generator constructs can provide this functionality; python's generators can be very conveniently used for this. So you might embed a python interpreter in C++ (or call your C++ from python, maybe a saner choice) and write stuff like:

def a_script():    do_something1()    do_more()    #return control while saving state    yield    #execution resumes at this point when the generator object's .next() method is invoked    do_something2()    #return control after doing somethng2    yield    #execution resumes here    ....

##### Share on other sites
you might also want to check out AngelScript, which has its own forum here at GameDev.net

##### Share on other sites
I have looked at Angelscript and it's possible that it's just what I want. There's very little in the way of tutorials and such, though. I'll keep poking at it, though. The same goes for GameMonkey, which seems similar in functionality to Angelscript (as far as I've looked into it).

I don't know anything about continuations or generators, but the example you gave is very close to what I want. Is it usually possible for a script to yield within a logical or looping construct and resume the same state it left afterward? What are some languages that have this feature?

##### Share on other sites
I would highly suggest looking at Squirrel which has some nice C++ bindings called SqPlus.

##### Share on other sites
Quote:
 I don't know anything about continuations or generators, but the example you gave is very close to what I want. Is it usually possible for a script to yield within a logical or looping construct and resume the same state it left afterward?
Of course, that's the whole point. The generator construct takes care of remembering the state so you don't have to.

Let's make two generators, one that makes even numbers and one that makes odd numbers. Notice they use a while loop:

def generate_odds ():    current = 1    yield 1    while True:        current += 2        yield currentdef generate_evens():    current = 0    yield 0    while True:        current += 2        yield current

Let's look at an example interaction:

>>> evens = generate_evens()>>> odds = generate_odds()>>> evens<generator object at 0x00B3A1C0>>>> evens.next()0>>> evens.next()2>>> odds.next()1>>> odds.next()3>>> odds.next()5>>>

Of course, generators are objects, so we can pass partially-executed scripts around and combine them in different ways. let's make a generator which interleaves the results of two other generators:

def interleave_generators(gen1, gen2):    state = 0    while True:        if state == 0:            state = 1            yield gen1.next()        else:            state = 0            yield gen2.next()

We can call this with two brand new even and odd generators, or with the half-executed generators 'evens' and 'odds' we defined previously (it'll start interleaving them from where we left off, that is, 4 in the evens generator and 7 in the odds one):

>>> all_numbers = interleave_generators(generate_evens(), generate_odds())>>> all_numbers.next()0>>> all_numbers.next()1>>> all_numbers.next()2>>> previously_defined = interleave_generators(evens, odds)>>> previously_defined.next()4>>> previously_defined.next()7...

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627719
• Total Posts
2978797
• ### Similar Content

• By KARTHI
I planned to make a game like star citizen. In this game player can travel through the space ,explore the planets, Hunt the different creatures, drive the space ship, explore different regions in universe, destroy the space stations and also player can go anywhere in the universe and meet aliens and so on
Did you like this idea?
Please give me reply so that I can easily understand what you want.
🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔🤔

• Your home planet was attacked. Now you have to use your spaceship to battle the invaders. Powerful 3D arcade with outer space background. Very addictive. Good luck!

• Attack Of Mutants is an adrenaline - powered and bloody shooter in with lots of horror and action! Beat back the waves of opponents. The game features a lot of weapons and types of enemies. Show them what you are capable of. Prove your power and strength!

• By sprotz
I like unity3d but the installation size is too big. the package itself is 1GB and the installation is 5GB. What are some good, easy 3d game engines similar to Unity that have smaller file sizes? Excluding engines that lack editors like level editors, world editors etc, with an easy enough scripting language, physics and good documentation.

•
I'm looking for a team to help me out with a 3D platformer. Basically, you jump between platforms with parkour elements and you fight enemies with a mix of melee and ranged attacks. This is purely a hobby project. I'm not promising any payment, ever. You can do it for experience, to learn, for fun, whatever, as long as you don't expect to get paid. Right now I need a 3D modeler and animator. Reply or email me at jordestoj@yahoo.com if you're interested. Thanks.

• 10
• 9
• 21
• 14
• 12