Dev Blog

Hi, this is the Stranded III development blog (see also Forum Thread, Comment Thread).

Overview (115 Entries)

Entry 60 - Drawing the Line: Script vs Code - January 15, 2017

2017
Welcome to dev blog entry number 60 and also the first one in 2017!
I hope you all had a happy new year.

Drawing the Line: Script vs Code
I made 3 bigger games in my life which can be modified a lot with scripting. Stranded II, Counter-Strike 2D and Carnage Contest.
They all have their own scripting system. They all differ in a way but they all work quite well.

Stranded II was designed with scripting in mind from the beginning. Several things in the actual game are done in script. The whole adventure is scripted too.
Stranded II Script (S2S) however is very slow so I took care that scripts are only executed when it's really necessary.
To make that possible I defined a number of events to which you can attach scripts by writing an event handler.

Scripting wasn't planned from the beginning for Counter-Strike 2D. It has been added later - on top of an already "complete" game.
This means everything in Counter-Strike 2D is game code, but you can influence and modify the normal behavior by hooking into the game when certain things happen.
CS2D's hooks are basically what Stranded II's events are. They are slightly different but it's the same idea.
Lua scripts only run on server side in Counter-Strike 2D though. A game client never executes a single Lua command.

Carnage Contest heavily relies on Lua scripting.
All weapons and some objects in the game are actually completely scripted in Lua.
These scripts run all the time - meaning each frame.
And it works. There's a weapon in Carnage Contest called "Arrow Rain". It spawns a shitload of arrows in the sky. Every single arrow is drawn, moved and updated with Lua - at a good and stable frame rate.
Additionally you can script game modes and "game enders" to influence the game even more. Scripts are even transferred to other players so they can play with your custom weapons.

For Stranded III I wanted to go even a step further. I wanted to make basically everything modifiable.
One way to achieve this is to write most of the game completely in script instead of code so people can touch and modify all the stuff.
That's the way I went for. Unfortunately.
The fully scripted menu - which contains a lot of complex UI elements - proves that this approach works fine performance wise.
The problem is that the Lua scripts for the UI system are kind of crazy - at least compared to the simple scripts in my other games.
They are too complex for my personal taste and probably so complex that many people who want to mod the game are scared when they see them.

There are also more problems with scripting everything: I have to expose everything to the Lua API.
In some cases I really don't want to expose certain things though because it's dangerous. The interface to enter U.S.G.N. login data for example.
Someone could very easily write a mod which steals your data because even the input field itself is fully scripted.
It also leads to instability: When you screw up a part of the UI system script, the whole game will explode and you won't be able to interact with it anymore because the UI script can't run anymore.

Apparently I've drawn the line for the scripting API at the wrong position. I did too much stuff in script, resulting in overly complex scripts with too much access and too many responsibilities.

How to solve this? The answer is simple: Move more parts to code again and do less stuff in Lua.
C# (the language Stranded III is developed in) is way better for writing complex stuff because it is more strict and strongly typed.
In my opinion Lua isn't the best choice for complex things. It is still nice however for quick development of small to medium software artifacts because of its open and dynamic table system.

The painful consequence of all this: I have to port the UI system from Lua (over 4.5k lines for the system itself + over 2.2k for actual game menus) to C#. Afterwards I'll throw the fancy Lua UI scripts into the trashbin. Ouch.
But hey, I learned some crazy Lua tricks while writing the UI.
Moreover it helped me to develop a powerful 2D Lua API for Stranded III which can be used for modding.

Another consequence: To speed up development I'll go for a more code-heavy approach in general now.
This means that some aspects of the game might be less modifiable at first.
This can speed up development because writing a modifiable system with Lua API is more effort.

Game Suggestion: Raft
I found a little game which is worth a try. It doesn't have much content and you can probably get to know everything it has to offer in 1-2 hours of play time but it's a very fun and interesting idea.
Raft is being developed by three students from Sweden (according to Rock Paper Shotgun). It's all about surviving on a raft on the ocean. You have to eat, drink and defend yourself against sharks. The probably most interesting part: You can extend your raft with flotsam.

It's available for "pay what you want" which includes the possibility to simply get it for free.
> Get Raft

Disqus

blog comments powered by Disqus