Assigning stats through LUA to a node.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Jesterstear
Posts: 18
Joined: Mon Jan 19, 2009 9:14 pm

Assigning stats through LUA to a node.

Post by Jesterstear »

Hey guys, I am wondering on how to go about with this.

I currently have LUA controlling my game and want to assign stats to units.

Everything I have come up with has either crashes the game or just simply didn't work.

I am a total noob to OOP so I am trying to maneuver through it with as much tutorials as possible, but I just don't see how this can help me.

Would editing the sources for Irrlicht and adding stats to a node help me accomplish this? It seems like the only way right now.

Sorry if this is a bit vague, I would be happy to explain things more.

Thank you for any help!

-Mike
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

Ok, from what I understand: What you want to do is assign things like HP or some other stat to a scene node.

The way I did this in my game is write what I call my ActorManager, it manages individual actors which have thier own code, variables, etc. You could make something similar for yours. Mine is heavily based off of Irrlicht's SceneManager.

Here's the basic gist of it:
The ActorManager manages a list of actors and runs thier code every time it's own run function is called.
The ActorManager run is manually called in the game's main while loop.
The ActorManager is actually an actor its self, with a null parent.

~DtD
Jesterstear
Posts: 18
Joined: Mon Jan 19, 2009 9:14 pm

Post by Jesterstear »

Yeah that seems like something I was going for.

I can't really work on it right now as VC++ is giving me a "application is not installed properly." And I cannot fix it, so I may have to reinstall VC++ later (I statically linked the dll or whatever and I have also installed the redist...still nothing, and it happened out of the blue).

NOTE: *NOOB ALERT*
Here is what I had in mine, there are something that cause a crash with LUA.

Code: Select all

#include "irrlicht.h"
using namespace std;
using namespace irr;

class state{
public:
	bool attacking;
	bool moving;
	bool idle;
	bool casting;
};
class Character{
	public:
			 int hp;
			 int maxhp;
			 int mana;
			 int maxmana;
			 int agility;
			 int strength;
			 int intelligence;
			 int attackmin;
		     int attackmax;
			 std::string name;

	void loadChar(std::string unitname, int loadHP)
	{
		this->name = unitname;
		this->hp = loadHP;
	}
	void changeHp(int hpAmount)
	{
		this->hp += (hpAmount);
	}
	void setHp(int hpAmount)
	{
		this->hp = hpAmount;
	}
	void setState(state newState, int stateNum){
		if(stateNum == 0) newState.idle = true;
		else if(stateNum == 1) newState.moving = true;
		else if(stateNum == 2) newState.casting = true;
		else if(stateNum == 3) newState.attacking = true;
	}
	void getName()
	{
	}
};
Is that how something like this would go about being done?
I then have LUA call

Code: Select all

int loadUnit(lua_State *L)
{
	Character unit;
	unit.loadChar(lua_tostring(L, 1), lua_tointeger(L, 2));
	return 0;
}
So that the unit can be a variable in LUA.

Setting attributes is done like

Code: Select all

int setHP(lua_State *L)
{
	//Character unit;
	//unit.loadChar(lua_tostring(L, 1));
	//unit.setHp(lua_tointeger(L, 2));

//if(unit.hp <= 0){
	//	node = smgr->getSceneNodeFromName(lua_tostring(L, 1));
	//	node->remove();}
	return 0;
}
It is commented out because I was fixing stuff.

Thank you for your tips.
Post Reply