Sign in to follow this  

Questions about Small

Recommended Posts

Hi guys, I have been playing with Small and I like it a lot, but I have some questions that maybe someone with more experience would answer. For the game I am working on, I have licensed the Cipher engine ( I replaced DirectInput and window management by SDL, DirectSound by OpenAL, and the network functions by SDL_net, to make it work on Linux and MacOSX systems. Now, I want to add a good scripting engine to it, so the game logic is coded in 100% portable scripts instead of the dlls you normally use in Cipher (it works like in the Quake engine: one dll for the server, another for the client, and one more for the user interface), and to implement a language that allows for faster development than C. I found Small perfect for the purpose. Considering that it is based on C, but with simplified syntax, it would fit perfectly the structure of Cipher, which is also coded in C. I would only have to export all the functions of the engine to the virtual machine, and that would be all. But I have encountered a problem. Small does not support any type of structures, but this is not a problem because the way it works with enum lists is very powerful. You would declare an enumerated list like:
enum myList
And then create an arraw which will hold this data:
new myVar[myList]
myVar[myField1] = 45
myVar[myField3] = myVar[myField2]
So you have a very limited support for structures using arrays and enum lists. Well the problem is the following. Imagine that I have this two enum lists:
enum viewinfo_t
   x, y, w, h,             // Viewport position and size
   fov_x, fov_y,           // FOV value fo the camera
   posx, posy, posz,       // Camera position
   pitch, yaw, roll,       // Camera angle
   fogstart, fogend,       // Fog begin and end positions
   fogr, fogg, fogb        // Fog color (RGBA format)

enum iteminfo_t
   type,             // Type of item
   model,            // Handle to the model
   posx, posy, posz, // Position of the node
   pitch, yaw, roll  // Angle of the node
Then, if I create an array to hold information for an item, and try to modify its 'roll' field, like this:
new item[iteminfo_t]
item[roll] = 20
I get the following error:
array index out of bounds (variable "item")
This is because it takes the value of 'roll' from 'viewinfo_t' (which is 11) instead from 'iteminfo_t' (which is '7'). As 'iteminfo_t' is an array which 8 indices, it gives that return. I thought that using 'item[iteminfo_t:roll] = 20' should fix it, but it gives the same error... does anyone know how to do this?

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
when i look at the features list of the engine, there is the following:

- Custom version of lcc C compiler to generate byte code version of game code for execution of Cipher Virtual Machine.
- Virtual machine allows same game code to securely run on multiple platforms.

so it should possible to compile your gamecode not only as a .dll but also as bytecode to run in the engine's virtual machine, like in quake 3

Share this post

Link to post
Share on other sites
The first thing that occurs me when reading is post is the question of why you're not using a language that has native support for structures. I'm not familiar with small, but from your post it seems as if you've come up with a clever solution, but as the feature you're wanting isn't supported by the library, you're likely to encounter problems as you go, each probably requiring more hacks to fix. As such, the project could become messy quickly - which would be a shame as it sounds like you have a great grasp on the project so far. If you want to look at a couple of C-like scripting languages you could look at AngelScript, GameMonkey and even Lua - each of these has native support for structures (or tables in GM/Lua).

Good luck


Share this post

Link to post
Share on other sites
@Anonymous Poster: The virtual machine provided with Cipher seems too slow for me, and it's just plain C. I would like a C-like syntax scripting language, but much simplified for faster development. Small is perfect for this purpose.

@evolutional: Yep, I have been looking for alternatives to Small these days. I chosed Small at first because it was very similar to C, and would fit in Cipher perfectly. Antoher reason is that it is the best documented scripting engine I have found (although this changes with the book "Programming in Lua"). I have found two great alternatives: Io Language ( and GameMonkey. The first one works on all the platforms I am interested in, has anybody sucessfully used GameMonkey on MacOSX?

I took a look at GameMonkey and loved it's syntax. Very similar to Lua, but much more C-like (Lua looks Basic-like to me). It would be a great option for Cipher.

Share this post

Link to post
Share on other sites
Ok, Squirrel had a lovely syntax, I really like it a lot, but by now, I have finaly decided to use Lua. Why? Well, everyone seems to love it, and its performance and stability has been proven on many commercial games (the list is simply endless).

Implementing Lua in Cipher has been extremely easy, and it works like a charm. I used toLua++ to generate the wrapper functions needed, and have exported the functions to Lua in an object oriented way, so what in the standard C version of Cipher is re_AddItemToScene(), in Lua it is scene.addItem() :)

I have not exported all the Cipher API to Lua yet, but it's coming along nicely.

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