more skills

Posted By: LewyT

more skills - 11/09/11 02:47

Hello and greetings from a new forum member.
I am new to gamestudio and lite-c.
I have read and played with the tutorial workshops and modified one to start building my own game
It appears I will need more "skills" for my player entities than what is available.
After searching the help file I found "atypes.h" and modified the line that reads "skill[100];" to "skill[200];"
That didn't cause any errors so I wrote a few defines in my game file:
Code:
//  STATS
#define LIFE skill[101]
#define STRENGTH skill[102]
#define AGILITY skill[103]
#define MIND skill[104]
#define SPIRIT skill[105]

// VITALS
#define HEALTH skill[106]
#define MAXHEALTH skill[107]
#define HEALING skill[108]
#define WOUNDS skill[109]

#define STAMINA skill[110]
#define MAXSTAMINA skill[111]
#define STAMREGEN skill[112]

#define MANA skill[113]
#define MAXMANA skill[114]
#define MANAREGEN skill[115]



That didn't cause any errors so I used one in my entity action :
Code:
var ph;
action updatecharacter() // this is called when the entity is created
{ 
	// initialize stuff
	my.HEALTH = 100;

	while (1) // action loop
	{
		ph = my.HEALTH
		// all the character movement and action handling in here
		wait(1);
	}
}



that didn't cause any errors either but when I display the info in a panel it shows the value is zero (0) when it should be 100
Code:
PANEL* panDisplay =
{
	digits(5, 20, "health = %0.f", *, 1, ph);
	flags = SHOW;
}



What am I missing here?
Can I simply not use skills over 100?
please note these code snippets are not my exact code but abbreviated form
Posted By: LewyT

Re: more skills - 11/11/11 00:19

Well, I haven't found an answer to my question yet.
But I did just notice line 4 of atypes.h:
// DO NOT move or edit this file!
woops, ok so I guess I can't do that
for some reason I thought I read somewhere I could edit it as long as I copied it to my work folder...
it must a different include file

so anyway I'm back to square 1
I need a way to store more data for my character entities
I've tried adding a new member to the ENTITY struct but that sometimes crashes the game and sometimes the data is corrupted.
I'm guessing the engine has some hard coded references to the structs that makes editing that file hazardous.

any suggestions?
Posted By: Superku

Re: more skills - 11/11/11 00:49

The engine with all its structs is already compiled (so changes won't have any effect), I think atypes.h and similar header files are just information for the compiler.

The best way to store more data is probably creating structs (see manual) and saving struct pointers in entity skills.
Posted By: tzw

Re: more skills - 11/11/11 07:40

it's a offset problem
Posted By: LewyT

Re: more skills - 11/11/11 12:27

ok, Thanks guys
I'm going to try the struct and let you know if I have any problems.
I'm not very familiar with C style syntax but I understand I will need to malloc() the pointer
my main concern is how I will reference the data
can I do something like this?
theEntity.theSkill.PlayerStat = 100;
Posted By: LewyT

Re: more skills - 11/13/11 22:58

Ok, I guess I don't know how to implement this.
I'm trying to learn from another thread but I can't seem to get it right.

so I defined my struct (I think this part is right)
Code:
typedef struct INFO {
	var HEALTH;
	var MAXHEALTH;
	var HEALING;
	var WOUNDS;
} INFO;


also defined the skill:
Code:
#define info 		skill37


I assume the next step is in my entity action to set my.info to a pointer to an instance of INFO
I also want to set and retrieve the values of HEALTH, MAXHEALTH, etc
I've tried a few things but I always get errors trying to set those members.

I should probably point out that this is my first time using pointers.
My previous programming experience is with simpler languages and scripting languages.
I'm trying to learn Lite-C because those other languages don't seem to have the power I need.
Posted By: EvilSOB

Re: more skills - 11/14/11 02:37

I cant see any reason why its would be a difficult conversion,
entity to struct that is. But then again, Ive had a lot of practice...

Basically, do the same as the other thread says, just replace ent_create with sys_malloc.
Code:
player.skill37 = sys_malloc(sizeof(INFO));
or
player.info = sys_malloc(sizeof(INFO));
//remember sys_malloc does NOT fill the values with zero's)



Then when you want to access the info-data, use the following.
Code:
INFO* temp_info = (INFO*)player->info;
var temp_health = temp_info.HEALTH;



Or, if you want to get really tricky...
Code:
var temp_health = ((INFO*)player->info).HEALTH;




Best of luck...
Posted By: LewyT

Re: more skills - 11/14/11 03:16

Thanks! that worked great.
Posted By: EvilSOB

Re: more skills - 11/14/11 03:40

S'cool dude.
Posted By: gri

Re: more skills - 11/15/11 10:15


does we have to care about freeing the memory before closing the engine with this solution ?
Posted By: WretchedSid

Re: more skills - 11/15/11 11:36

gri, you should never care about freeing the memory if it lives throughout the applications lifecycle! The OS has a much better way to get rid of the memory at once, once your application exits! However, if you have memory that doesn't live with your application, you really should free it!
Posted By: LewyT

Re: more skills - 11/15/11 13:57

I agree with JustSid,
If you use the same object(s) throughout the game you won't need to free them.
If you are creating a lot of pointers that need to be allocated and then all or many of those objects are discarded during the game then you probably should make a habit of freeing them when they are no longer used.
Obviously larger objects such as entities take more memory and thus more important to free when disposed of.
In my example the object is a struct attached to my character. Even when the character dies and has to restart, I will still be using the same "info" pointer so I won't free it during the game. Even if I were "switching" characters, I could probably still use the same struct and just load in the new character's data from a file.
However, if I make this a multiplayer game and then if players join and leave the game before it is over, their info should probably be freed when they exit.
In the help file, it says about level_load:
Quote:
All current entities in the old level are removed, thus all entity pointers referring to them can't be used anymore.
so I'm not sure how that will effect my situation.
Posted By: Superku

Re: more skills - 11/15/11 14:28

I think the on_ent_remove event is a pretty convenient way to free allocated memory that is saved in entity skills:

#define path skill90

ent.path = sys_malloc...

void on_ent_remove_event(ENTITY* ent)
{
if(ent.path) sys_free...
}

On the downside, you should not use the specific skill for anything else.
Posted By: EvilSOB

Re: more skills - 11/15/11 19:00

Originally Posted By: SuperKu
On the downside, you should not use the specific skill for anything else.

Or at least not for real numbers, only unique sys_malloc'ed structures...
© 2024 lite-C Forums