Skip to main content
GameDev.net gamedev.net
🔒 Locked

Embedding a script language into my MUD

Started by Toolmaker Jan 24, 2005 at 5:22 AM 13 replies 3k views
Original Post
Toolmaker
Toolmaker
I'm almost up the point on where I want to add NPCs into my MUD. However, for most behaviour of the NPCs I want to use a scripting language rather than a hardcode it in the engine. At this point I haven no idea what scripting language to use, except that it isn't going to be Lua. Ideas for this? It would be nice if it had C/C++ syntax(And possible support for classes in the scripts themself). Also, it should be easy to embed into my current engine. As a next question, I don't really have an idea on where to start with the scripting themself. I can imagine I need a bunch of "events" for each NPC such as: OnRoomEnter, OnRoomLeave, OnFight(Other player/NPC is attacked), OnAttack(NPC being attacked), OnUpdate, OnDeath(NPC died), OnKill(Opponent NPC died) and perhaps OnItemDrop and OnItemPickup. Toolmaker
 
evolutional
evolutional
I'm having a lot of success with GameMonkey Script lately. It's got a C style syntax and takes a lot from Lua, without being Lua itself. I find the user API to be a lot better than Lua's, which I personally find clumsy and awkward with important things such as passing of parameters to scripts. I've thrown some tutorials up for GameMonkey Script in the relevant section of my site if you're interested.

Otherwise, I'm also using SpiderMonkey - Mozilla's embeddable &#106avascript engine, which is very much like C++/Java in syntax.
intransigent-seal
intransigent-seal
Why isn't it going to be Lua? This may be important; after all, if we know your reasons then perhaps we can avoid making suggestions that will end up just having the same problems.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Toolmaker
Toolmaker
I totally disliked the API of Lua. It wasn't really programmer friendly when calling script functions, etc.

I'll take a look at GameMonkey. One question tho, how fast is it?

And John: I've considered PLP ;)
EDIT: Evolutional: GM looks really neat! Thanks for that

Toolmaker
 
evolutional
evolutional
Yeah - the programmer API was what really pained me when trying Lua. I know you can get things such as ToLua to ease the pain, but IMHO the language should be painless right out of the box. To many, it probably is but I found it unbearable because of the stack handling.

GM is pretty fast, it's probably slightly slower than Lua but from the speed tests I've seen people talk about on the GM forums there doesn't seem to be much in it. The developers of the language will help you out with any problems you have on their forums, which is useful.
intransigent-seal
intransigent-seal
Slightly off-topic, since Lua has been ruled out, but for those of you that like Lua but hate the Lua api, I would suggest you have a look at LuaPlus, which provides an (imho) excellent api to use (as well as various other enhancements).
[I'd suggest getting the version from the subversion repositry rather than the prepackaged versions, as they don't seem to have been updated recently]

Edit: I would suggest other languages, but I don't have experience with embedding any others, so really, a google search would be as useful as I could be.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Josh Yelon
Josh Yelon
Here's a question: is there a reason the MUD isn't written entirely in a high-level (scripting) language? On such a project, I wouldn't use C++ at all.

- Josh Yelon-- Distribution Maintainer, Panda3D Engine
Zahlman
Zahlman
Have you considered rolling your own? Base it off the syntax users would actually enter in order to perform commands, and add hooks to determine things like room name/ID etc, and control flow structures. At runtime, treat the script as a list of input commands. Go to the appropriate point when an event is triggered, and start reading commands. For each, if it's a control flow structure then do an appropriate bit of magic, otherwise just feed the line to the same code that processes user commands. Great code reuse :) (For bonus marks, expose this scripting API to users for bots ;) )

So it might look like: (here * is used to mark keywords, such that you know that that line isn't supposed to be a command; % is used for a variable substitution into a command)
*EVENT wander:*LABEL tryagain*CHOOSE direction FROM north east south west%direction*IF_FAIL_GOTO tryagainsay nothing to see here, I'm just an innocent mob wandering aimlessly...


(Then you need to set up your Mob objects with a common superclass to Player objects, so that they can be interacted with in similar ways... and set their output display port to a null object, so your command parser can generate error message and send them to the Mob, which subsequently ignores them.)

You probably don't really need much, so it's within the realm of possibility to do this work yourself. You could also bytecode-compile ahead of time, and have a bytecode which represents "do variable substitution into this string and pass it to the command parser".
Retrep
Retrep
>> As a next question, I don't really have an idea on where to start with the scripting themself. I can imagine I need a bunch of "events" for each NPC such as:
OnRoomEnter, OnRoomLeave, OnFight(Other player/NPC is attacked), OnAttack(NPC being attacked), OnUpdate, OnDeath(NPC died), OnKill(Opponent NPC died) and perhaps OnItemDrop and OnItemPickup.

Have you looked into state machines? From the sounds of it, they'd be perfect for what you want to do, and you could expose them using a scripting language. This is a nice introduction: http://www.ai-junkie.com/architecture/state_driven/tut_state1.html from an equally nice book :)
Rob Loach
Rob Loach
I played around with LuaPlus a couple of days ago as I thought it would be "Plus" better then the original Lua. I didn't get into binding or anything like that though... Been trying to compile GM and have been having some troubles. I guess it's just the GCC and Dev-C++ combo that's a killer. I'll have another go at it today and see if I can have it do something interesting.

Quote:
Original post by Brandon N
Have you tried Python?
The reason I'm not using that is because it's just so ugly. I need something that's powerful and clean. Not just powerful [smile]. GameMonkey takes off of C/C++ so it's a definate option.
Rob Loach [Website] [Projects] [
evolutional
evolutional
Quote:
Original post by Rob Loach
Been trying to compile GM and have been having some troubles. I guess it's just the GCC and Dev-C++ combo that's a killer. I'll have another go at it today and see if I can have it do something interesting.


You need to use the gm_Config_p.h from the win32_gcc directory. If you have any problems, PM me over the weekend and I'll hook you up with a simple makefile.

Rob Loach
Rob Loach
Quote:
Original post by evolutional
You need to use the gm_Config_p.h from the win32_gcc directory. If you have any problems, PM me over the weekend and I'll hook you up with a simple makefile.
Hey.... I got it compiled with the correct gm_Config_p.h, but got some hardcore linker errors:

gmDebugger.o(.text+0x26f):gmDebugger.cpp: undefined reference to `gmDebuggerBreak(gmDebuggerSession*, int, int, int)'gmDebugger.o(.text+0x298):gmDebugger.cpp: undefined reference to `gmDebuggerRun(gmDebuggerSession*, int)'gmDebugger.o(.text+0x2c1):gmDebugger.cpp: undefined reference to `gmDebuggerStop(gmDebuggerSession*, int)'gmDebugger.o(.text+0x31a):gmDebugger.cpp: undefined reference to `gmDebuggerSource(gmDebuggerSession*, int, char const*, char const*)'gmDebugger.o(.text+0x343):gmDebugger.cpp: undefined reference to `gmDebuggerException(gmDebuggerSession*, int)'gmDebugger.o(.text+0x384):gmDebugger.cpp: undefined reference to `gmDebuggerBeginContext(gmDebuggerSession*, int, int)'gmDebugger.o(.text+0x457):gmDebugger.cpp: undefined reference to `gmDebuggerContextCallFrame(gmDebuggerSession*, int, char const*, int, int, char const*, char const*, int)'gmDebugger.o(.text+0x4b9):gmDebugger.cpp: undefined reference to `gmDebuggerContextVariable(gmDebuggerSession*, char const*, char const*, int)'gmDebugger.o(.text+0x4c9):gmDebugger.cpp: undefined reference to `gmDebuggerEndContext(gmDebuggerSession*)'gmDebugger.o(.text+0x4d9):gmDebugger.cpp: undefined reference to `gmDebuggerBeginThreadInfo(gmDebuggerSession*)'gmDebugger.o(.text+0x530):gmDebugger.cpp: undefined reference to `gmDebuggerThreadInfo(gmDebuggerSession*, int, int)'gmDebugger.o(.text+0x53d):gmDebugger.cpp: undefined reference to `gmDebuggerEndThreadInfo(gmDebuggerSession*)'gmDebugger.o(.text+0x566):gmDebugger.cpp: undefined reference to `gmDebuggerError(gmDebuggerSession*, char const*)'gmDebugger.o(.text+0x58f):gmDebugger.cpp: undefined reference to `gmDebuggerMessage(gmDebuggerSession*, char const*)'gmDebugger.o(.text+0x5d0):gmDebugger.cpp: undefined reference to `gmDebuggerAck(gmDebuggerSession*, int, int)'gmDebugger.o(.text+0x5e0):gmDebugger.cpp: undefined reference to `gmDebuggerQuit(gmDebuggerSession*)'dllwrap.exe: no export definition file provided.Creating one, but that may not be what you wantdllwrap.exe: c++ exited with status 1make.exe: *** [gamemonkey.dll] Error 1


Went through it thoroughly but couldn't find anything wrong with it. Could you think of anything?
Rob Loach [Website] [Projects] [
evolutional
evolutional
Yeah - don't compile the gmDebugger.cpp file with it. It's an interface class that I think you have to implement yourself.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.