Jump to content

  • Log In with Google      Sign In   
  • Create Account

sethhope

Member Since 12 Jan 2013
Online Last Active Today, 09:45 PM

Topics I've Started

Weird if() behavior

16 October 2014 - 09:51 PM

So I've been working on creating my lua script class interface, and I ran into an interesting crash-inducing problem.

lua_State* SCRIPT::runInit()
{
	log->debugData("Running init function");
	lua_getglobal(L, "init");
	int er = lua_pcall(L, 0, 0, 0);
	if(er != 0)
	{
		log->logData("Pcall error", er);
		log->logData("Failed to run init function", lua_tostring(L, -1));
		return L;
	}
	log->debugData("Ran init function");
	return L;
}

When I run this, it should call the "init" function. If it succeeds, er should equal 0, thus bypassing the if statement and going right to "log->debugData("Ran init function");" 

 

Here's the init function in the lua file:

function init()
	MainScene:SLog("Init DOES in fact exist...")
	MainScene:addMesh("sibenik/sibenik.obj", 0, 0, 0, 0, 0, 0, 1, 1, 1)
end 

However, when I DO run this, here's the output directly from the log file:
 

DEBUG: Running init function
Init DOES in fact exist...
Loading mesh : sibenik/sibenik.obj
DEBUG: Loaded mesh
Pcall error : 0

Then it errors on the second log->logData() due to the empty lua_tostring(L, -1). 

Note that the Pcall error is returning 0... This means that it shouldn't have gone into the if statement at all, however, it does anyway...

Is it a problem with my compiler?


Lua and Irrlicht compilation conflicts

07 October 2014 - 07:54 PM

So I have an application that has irrlicht handle graphics, and lua handle the scripting. I've worked extensively with lua before, but am only now diving into irrlicht. Currently I have an application that SHOULD open a window and run a test lua script. When I run the application, it throws a "PANIC: unprotected error in call to Lua API (bad conversion number->int; must recompile Lua with proper settings)." I have recompiled lua several times with several different settings (ansi, LUA_ANSI, and soft float) but nothing seems to work. Then I got the brilliant idea to comment out everything irrlicht, since it's the only difference from my other lua-based project so far. Once commented out, the lua works fine. When the lua is commented out, the irrlicht works fine. Together, it throws an error. 

As far as I've found, the error is being thrown when I call "luaL_openlibs(L)" in the "lua_checkversion()" function. I'm not sure how to fix this, or if lua and irrlicht simply aren't meant to be.

 

Ideas?


Interactive Tech Demos Turned Games

29 September 2014 - 12:43 PM

So recently I began looking back on my past games that I have finished. Most of them being either very simple 3D wireframe games or 2D shooters. They don't look, feel, or really even play impressively at all. They seem very standard. However, to me, they are my pride an joy.

 

I am a programmer who is more obsessed with using the least RAM and the least processing power to get something accomplished. As a systems programmer or a backend guy, that's perfectly fine. But as a one man game development team, that leads to some interesting issues.

 

As of late, I have gotten ideas for some good games that I really want to make, however, I have a problem with getting past the "tech demo" phase and into the actual game phase. I spend more time developing memory saving algorithms or finding ways to cut down on processing and less time on developing a game. In the early stages of game development, this may not seem like a problem, however, I have been encountering this problem subconsciously for over 5 years now!

 

I have been programming for the better part of 9 years, and have over 5 years in game development, but still struggle to get a basic 3D game to come together using modern technology.

 

I have no problems banging out a flight simulator for a watch built out of 8 bit AVR chips. I have no problems rattling off entity code for 10,000+ enemies on screen at once. I DO have a problem with putting these things to use within a game. 

 

Not sure if I'm making any sense at all, but if you have any advice for how I can become a better game developer and less of a backend memory-fixer, please let me know. 


Speaking of disasters...

28 September 2014 - 11:46 PM

So for last weeks GDNJam, I added alot of messy, inefficient, and all around ugly code to my engine just for the sake of having "working" features in the quickest time. That lead to some very... interesting lines of code.

For example:

 

I have a struct "TEXT" that holds a string, color code, id number, time for timed deletion, and the x, y position of the text. These TEXT types are then stored in a vector to be later referenced and edited by their ID number. Well, when it came down to deleting them, no matter what I tried, I couldn't get a clean way to compile. That's when I resorted to:

gui->editText(key, " ");

That's right. Instead of freeing the memory and deleting it, I actually changed the value of JUST THE STRING to a space.

 

And another one from the engine in the AI character code this time:

Character* Scene::getCharacter(int id)
{
	for(std::vector<Character *>::iterator it = c.begin(); it < c.end(); it++)
	{
		if((*it)->id == id)
		{
			return (*it);
		}
	}
}

Please note the lack of return if the id doesn't exist... 

 

and don't even get me STARTED on the startup.lua file... 

if aiTime >= 2 then
			aiTime = 0
			local pX = scene:getPlayer():getX()
			local pY = scene:getPlayer():getY()
			local pD = scene:getPlayer():getDir()
			if T1:getMeta("alive") == "true" then
				if collide(T1:getX(), T1:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T1:getY() > pY then
						deltaY = deltaY - 1
						if T1:getX() > pX then
							deltaX = deltaX - 1
						end
						if T1:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T1:getY() < pY then
						deltaY = deltaY + 1
						if T1:getX() > pX then
							deltaX = deltaX - 1
						end
						if T1:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == LEFT then
					if T1:getX() > pX then
						deltaX = deltaX - 1
						if T1:getY() > pY then
							deltaY = deltaY - 1
						end
						if T1:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == RIGHT then
					if T1:getX() < pX then
						deltaX = deltaX + 1
						if T1:getY() > pY then
							deltaY = deltaY - 1
						end
						if T1:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T1:setPos(T1:getX()+deltaX, T1:getY()+deltaY)
			end
			if T2:getMeta("alive") == "true" then
				if collide(T2:getX(), T2:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T2:getY() > pY then
						deltaY = deltaY - 1
						if T2:getX() > pX then
							deltaX = deltaX - 1
						end
						if T2:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T2:getY() < pY then
						deltaY = deltaY + 1
						if T2:getX() > pX then
							deltaX = deltaX - 1
						end
						if T2:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == LEFT then
					if T2:getX() > pX then
						deltaX = deltaX - 1
						if T2:getY() > pY then
							deltaY = deltaY - 1
						end
						if T2:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == RIGHT then
					if T2:getX() < pX then
						deltaX = deltaX + 1
						if T2:getY() > pY then
							deltaY = deltaY - 1
						end
						if T2:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T2:setPos(T2:getX()+deltaX, T2:getY()+deltaY)
			end
			if T3:getMeta("alive") == "true" then
				if collide(T3:getX(), T3:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T3:getY() > pY then
						deltaY = deltaY - 1
						if T3:getX() > pX then
							deltaX = deltaX - 1
						end
						if T3:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T3:getY() < pY then
						deltaY = deltaY + 1
						if T3:getX() > pX then
							deltaX = deltaX - 1
						end
						if T3:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == LEFT then
					if T3:getX() > pX then
						deltaX = deltaX - 1
						if T3:getY() > pY then
							deltaY = deltaY - 1
						end
						if T3:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == RIGHT then
					if T3:getX() < pX then
						deltaX = deltaX + 1
						if T3:getY() > pY then
							deltaY = deltaY - 1
						end
						if T3:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T3:setPos(T3:getX()+deltaX, T3:getY()+deltaY)
			end
			if T4:getMeta("alive") == "true" then
				if collide(T4:getX(), T4:getY(), pX, pY, 20, 20) then
					System_run("Scripts/die.lua")
				end
				local deltaX = 0
				local deltaY = 0
				if pD == UP then
					if T4:getY() > pY then
						deltaY = deltaY - 1
						if T4:getX() > pX then
							deltaX = deltaX - 1
						end
						if T4:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == DOWN then
					if T4:getY() < pY then
						deltaY = deltaY + 1
						if T4:getX() > pX then
							deltaX = deltaX - 1
						end
						if T4:getX() < pX then
							deltaX = deltaX + 1
						end
					end
				end
				if pD == RIGHT then
					if T4:getX() < pX then
						deltaX = deltaX + 1
						if T4:getY() > pY then
							deltaY = deltaY - 1
						end
						if T4:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				if pD == LEFT then
					if T4:getX() > pX then
						deltaX = deltaX - 1
						if T4:getY() > pY then
							deltaY = deltaY - 1
						end
						if T4:getY() < pY then
							deltaY = deltaY + 1
						end
					end
				end
				T4:setPos(T4:getX()+deltaX, T4:getY()+deltaY)
			end
		end

All of these things have been fixed since their creation, but I figured they were noteworthy for posting here.

Any ugly, disastrous code that you guys have from a contest or timed event?


Lua issues: script loading

02 July 2014 - 06:19 PM

So I began implementing Lua into my 2D game engine and realized that it becomes increasingly difficult to run a script every update and a script every render while carrying over globals and not re-loading the script every time. What I mean by that is, I either have to load the script on EVERY update cycle and EVERY render cycle, OR I don't carry globals over by creating separate lua_State s. Any ideas, or am I just missing something HUGE with lua?


PARTNERS