Sign in to follow this  
Kyall

Scripting Language for a Game

Recommended Posts

My basic question is what is a good scripting language that already exists to use to make game scripting available to level designers that follows these requirements:

No code bloat. It needs flow control, math, events & timing and absolutely nothing else. The following code for example would be fired on a game event to control the flow of the game rules

[CODE]on X:
y = y - 1
if y == 0:
timeout 5s game_fail()[/CODE]

Class based. Not so the level designer can write new classes, but so that they can override already existing classes with new members, new values for member properties. The following example will override Foo, which is possibly an entity, and changes it's max speed to 5. So what this will do is any instance of class Foo in this level will have it's maximum speed overridden to 5

[CODE]class Foo:
max_speed = 5[/CODE]

Level focussed. A scripting language that allows just 1 script file for a level, and is designed not to be a programming language, but a scripting langugae, in that it's more like writing a script for a scene then it is coding a bunch of stuff.

Not compiled. Or can be recompiled at run-time. Run time editing is the goal here.

The reason we need these requirements is because the designer wants to be able to quickly iterate levels and I figure a scripting language to control level flow, although it comes with a learning curve, is the most productive fashion of doing this. Instead of what I've provided to people in the past for quick & dirty control like that which are data systems that are more like drag and drop coding than scripting. Which has ended in disaster, every time. I don't need a powerful scripting language, I need one that simply controls game flow, allows changing data the same way a reflection system would, and leaves everything else up to the compiled C++ code. For another example:

C++ Code [CODE]
class Enemy {
struct Settings {
double health, damage, speed;
Texture sprite;
};
double health;
}
[/CODE]

Scripting Class [CODE]
class Level3Enemy(CPP::Enemy):
settings.health = 5
settings.damage = 9
settings.speed = 15
settings.sprite = "../textures/enemya.tex"
def OnDamage(self,amount):
self.health -= amount
if self.health <= 0:
self.Die()

def Die(self):
# etc
[/CODE]

I do like python's syntax, but I don't know what scripting language can achieve the simplicity I want without requiring too much juggling to implement.

Thinking about it. The script basically needs to pull double duty:

As a property modifier for entities and as a flow controller & timer for levels. I have some scripts I wrote up to concept the idea of level control flow and I'll add those as follows:

Example 1: Satellite Uplink

[CODE]
// Survival Mission
global:
onstart(self):
timeout 1min self.spawnA()
timeout 5min self.uplink()

spawnA(self)
enemySpawnA.spawn(5)
timeout 1min self.spawnB()

spawnB(self)
enemySpawnB.spawn(5)
timeout 1min self.spawnC()

spawnC(self)
enemySpawnC.spawn(5)
timeout 1min self.spawnA()

uplink(self):
// mission successful

failure():
retryMission

satellite:
health=50
ondamage(self,amount)
self.health = self.health - amount
if self.health == 0:
global.failure()[/CODE][CODE]

// Group instances : This will over write the default parameters of the object
enemyA:
// Make them tougher than before by setting their inbuilt parametrs to different values
health = 5
damage = 2
// Create a new value for this class
oldspeed = 0
// Freeze this enemy in place for 3 seconds when damaged
ondamage(amount):
oldspeed = maxspeed
maxspeed = 0
timeout 3s self.resetSpeed()
// Allow the en
resetSpeed():
maxspeed = oldspeed
[/CODE]



[CODE]// Singular Item Instance
satellite:
health=50 // Custom variable
ondamage(amount): // Called by system when this is hit by fire
self.health -= amount // Decrement
if self.health <= 0: // If test
global.failure() // Call failure in global.failure to tell the system to bring up retry
[/CODE]

I'll probably replace the following with just entry & exit functions rather than having a global class

[CODE]
// Global item
global:
onstart(): // Called by system at start of level
timeout 5min self.finish() // Call a script function in 5 minutes time to finish the level
finish(): // Called automatically after 5 minutes
game.succeedMission()
[/CODE] Edited by Kyall

Share this post


Link to post
Share on other sites
As ApochPiQ said Lua and Python (among other languages) can be used to fulfill your requirements. I personally prefer Python over Lua for no technical reason, but because I feel more at ease while coding in python than in Lua.

Boost provides a quite powerful and easy-to-use classes for binding C++ and Python: [url="http://www.boost.org/doc/libs/1_50_0/libs/python/doc/"]http://www.boost.org...ibs/python/doc/[/url] Edited by doeme

Share this post


Link to post
Share on other sites
I've implemented a Python wrapper class from code project by Mindteck if you don't want to use Boost. The author is Vijay Mathew, and he's wrapper class I modded works wonders.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this