🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lua embedding

Started by
23 comments, last by Sneftel 21 years, 10 months ago
I''m using LUA for scripting in my engine.Although I''m not using it''s full power just yet,I did put out a little demo on my engine''s webpage that allows you to control a cube using a script file.The script that comes with the app just bounces the cube up and down but it should give you an idea of how to proceed in modifiying the script to make the cube do other things too.

My engine''s website is at:

bioengine.biosphereent.com

Goto the downloads section and grab the CubeScript demo and try it out.

Like I said,I''m not fully utilising LUA just yet.I''m trying to figure out the best way to have LUA do the AI for a game I''m working on.That''s when things will start to get really interesting

Hope this helps a little.Email me if you have any questions at thegecko@biosphereent.com

Cheers.

Advertisement
Do you have to pay a fee in order to use LUA in a commercial game?

Mindgamez Entertainment
quote: Original post by neurokaotix
Do you have to pay a fee in order to use LUA in a commercial game?

http://www.lua.org/copyright.html.

quote: Original post by HellRaider
However, the most recent Lua version still doesn''t support concurrent scripts.


That depends on what type of concurrency you want. The development version of Lua includes non-preemptive concurrency, and a patch for the current stable version will give you this too.

If you want preemptive concurrency, you can achieve this through threading, by maintaining a different lua_State for each thread. They are guaranteed not to step on each other''s toes.


Don''t listen to me. I''ve had too much coffee.
quote: Original post by HellRaider
I''m considering using Lua as the script language for a MMORPG server.

I''d like to code NPC''s AI with it, mainly.

However, the most recent Lua version still doesn''t support concurrent scripts.

That''s certainly something I need, since a server would control over 10.000 NPCs. It''d also make scripting much easier, as I would be able to have blocking functions such as "PromptPlayer".

The missing functionality I feel in Lua is a lua_run_chuck( unsigned char *chuck, unsigned long checksize, lua_State *L, unsigned long maxinstructions ) function, to limit the amount of instructions that a script can execute at once.

I couldn''t find any solution to this problem searching the web.

Can anyone here enlighten me? Or even confirm me that Lua isn''t for my project.

This is exactly the reason I don''t have Lua in my game. I can''t afford to have my designers locking up the game every time they accidentally make an infinite loop in an NPC script.

You might want to look on Google for the ''yield'' patch for Lua, written by Thatcher Ulrich, I believe. I exchanged a few brief emails with him, and while I decided that it still wouldn''t suit my needs, it might suit yours. (I think I came to decide that having a few thousand Lua_states would be too memory intensive.)

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
We are using LUA in our RTS massively for AI and mission scripting. You are able to control nearly everything from within the LUA scripts, from unit behaviour to thread creation to sound volumes. I''m really happy with LUA, it''s easy to use and executes fast. I guess LUA could suit your needs very well, but I have no experience with other better known script languages like python or tcl, so you might consider examining them as well.

Regards,
Matt
Hey Matt, would you be able to post any short examples of your scripts? A lot of people on the forums consider using Lua but rarely get any examples on how exactly it can be useful.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
i have a sample .. its from my 3d engine.


  function Abort(title,msg)	MessageBox(title,msg);	PostQuitMessage();endfunction InitWIN32()	-- createwindow name width height fullscreen	local ret = CreateWindow("Polaron",800,600,0);	if ret ~= 0 then		Abort("win32",Win32GetErrorString(ret));	endendfunction InitGL()	local ret = GLLoad();	if ret == 0 then		Abort("opengl","cannot start opengl");	end	GLInitCamera();	GLSetCameraPosition( 500, 35, 370,  501, 35, 370);	srt1 = GLCreateSkybox();	srt2 = GLSetSkyboxDimension(500,0,500,2000,2000,2000);	srt3 = GLSetSkyboxTextures("back.bmp","front.bmp","bottom.bmp","top.bmp","left.bmp","right.bmp");	if srt1 == 0 or srt2 == 0 or srt3 == 0 then		Abort("opengl","cannot load skybox");	end	local mapsize = 1024;	ret = GLInitHeightmap("terrain.raw",mapsize,16,"terrain.bmp");	if ret == 0 then		Abort("opengl","cannot load heightmap");	end	GLCreateQuadTree(mapsize,mapsize,5);	-- CreateMesh("dropship.3ds",500,30,500);	SetPlayerModel("tris.md2","rhino.bmp",500,30,500);endfunction ConfigureEngine()	-- set input 0 = win32 1 = directinput	SetInputType(0);	BindKey("w","forward");	BindKey("s","backward");	BindKey("a","strafe_left");	BindKey("d","strafe_right");	BindKey("c","console");	BindKey("lcontrol","crouch");endfunction debugmodes()	-- debug mode (1 to activate, 0 to deactivate)	-- 1 for wireframe	-- 2 for heightcells--	GLMode(1,0);endConfigureEngine();InitWIN32();InitGL();debugmodes();  


this script is to enable debuging using my engine. it just creates a level with 1 player model and lets you run in it.

Its my duty, to please that booty ! - John Shaft
This is a sample of the scripting language that myself and Eric are developing for the MindEngine... we're calling it MindScript

        #include func.mnd//main script filefunction main(){	int X	int Y	X=10	Y=30	if ( X < Y )	{		printl("Hey X is smaller than Y, go figure")	}		int newnumber	newnumber = testfunction( 10 , 15 , 20)		do	{		X = X + 1	}	loopuntil ( X > Y )	printl("Hey, Now X is 31!")}function testfunction( a , b , c ){	int temp	temp = a * b * c	return ( temp )}        


that was just a script showing some of the basics of the interpreter. We've added the ability to create functions that execute actual c++ code (compiled as part of the interpreter in separate header). This allows us to make a function called DrawSprite( imgname , x , y , x2 , y2... etc and then have it call like the actual D3DXSprite Draw command and pass it the variables to draw the sprite on screen. Perhaps not the best example of its growing usefulness but wait, I'll have better examples later and some real stuff for you to download =)

Mindgamez Entertainment

Edited for grammar =)

[edited by - neurokaotix on August 13, 2002 1:28:24 AM]
One thing I haven''t seen explained is how these scripts can call in game functions.

I would guess they would have to be C functions, or static C++ member functions, but how does the Virtual Machine that interperates the scripts call them?

Just curious.

This topic is closed to new replies.

Advertisement