Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Getting more than 100 skills without DLL #57218
10/07/05 13:52
10/07/05 13:52
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
I finded question about getting more than 100 SKILLS in one of the forum's thread. It can be done with DLL, fast and efficient. But If you can't deal with C++, you have to think about C-script...
Look at slow C-script version :
Code:

define Skill200, SKILL60; //define skill for handle storing
var GetEntRetVal; //must be global for execute...
entity* GetSetEnt; //pointer for SKILL box entity
string ExecStr; //string for execute command
string TempIntStr; //string for converting int->str
string PsEnt=<ps.mdl>; //create very small MDL5 entity with 4x4 skin (it takes ~296 bytes only)
action PsEntAction{ //action for our SKILL box
my.invisible=on; //invisible passable static
my.passable=on;
my.dynamic=off;
}

function GetSkill200(EntName, SkillNum){ //Get SkillNum value for EntName entity
GetEntRetVal=-1; //Set to ERROR
if (!EntName){return(GetEntRetVal);} //No entity, ERROR
if (SkillNum>100)||(SkillNum<1){return(GetEntRetVal);} //No Skill, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skill200==0){ //No entity for skill storing
GetSetEnt.Skill200=handle(ent_create(PsEnt,my.x,PsEntAction)); //create it
}
GetSetEnt=ptr_for_handle(GetSetEnt.Skill200); //get pointer to SKILL box
str_cpy(ExecStr, "GetEntRetVal=GetSetEnt.SKILL"); //prepare execute command
str_cat(ExecStr, str_for_num(TempIntStr, int(SkillNum)));
str_cat(ExecStr, ";");
execute(ExecStr);
return(GetEntRetVal); //return needed skill
}
function SetSkill200(EntName, SkillNum, SkillVal){ //Set SkillNum to SkillVal for EntName entity
if (!EntName){return(-1);} //No entity, ERROR
if (SkillNum>100)||(SkillNum<1){return(-1);} //No Skill, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skill200==0){ //No entity for skill storing
GetSetEnt.Skill200=handle(ent_create(PsEnt,my.x,PsEntAction)); //create it
}
GetSetEnt=ptr_for_handle(GetSetEnt.Skill200); //get pointer to SKILL box
str_cpy(ExecStr, "GetSetEnt.SKILL"); //prepare execute command
str_cat(ExecStr, str_for_num(TempIntStr, int(SkillNum)));
str_cat(ExecStr, "=");
str_cat(ExecStr, str_for_num(TempIntStr, SkillVal));
str_cat(ExecStr, ";");
execute(ExecStr);
return(0); //no ERROR
}
function RemoveSkill200(EntName){ //remove SKILL box, call this before ent_remove(EntName)
if (!EntName){return(-1);} //No entity, ERROR
GetSetEnt=EntName; //type casting ;)
if (GetSetEnt.Skill200!=0){ //No entity for skill storing
GetSetEnt=ptr_for_handle(GetSetEnt.Skill200); //get pointer to SKILL box
ent_remove(GetSetEnt); //and remove it
}
return(0); //no ERROR
}


For saving another 100 skills we create invisible passable static entity and use it as "SKILL BOX". Don't forget to remove it before removing 'parent' entity.
Example of usage (without error checking):
Code:

define MySkill6, SKILL6; //define name for skill6
define MySkill106, 6; //define another name for skill6, but this imagine skill106
...
SetSkill200(me, MySkill106, random(50)); //set my.skill106 to random value
me.MySkill6=20; //set my.skill6 to 20
...
your.MySkill6=GetSkill200(me, MySkill106); //set you.skill6 to my.skill106 (random value)
SetSkill200(you, MySkill106, me.MySkill6); //set you.skill106 to my.skill6 (20)
...
RemoveSkill200(me); //remove "skill box" entity before removing parent entity
ent_remove(me);
RemoveSkill200(you);
ent_remove(you);
...


That's all. If you want another 100 skills define one more skill for "skill box" handle and rewrite functions for set/get/remove.
But I don't know for what you may need 300 skills

Re: Getting more than 100 skills without DLL [Re: Lion_Ts] #57219
10/07/05 14:19
10/07/05 14:19
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Yes, you use somekind of a linked list by linking 2 entities together to retrieve a wider range of skills. But your script is a bit too complicated and slow. This is because you use execute and such things.

I use for instance these virtual placeholders to save classified data. For a racing game I defined a virtual track device for a car to save 17 skills. If I had to save them in the original entity's skills it would be too much consuming. By grooping it into one virtual object it is much easier to deal with.

Your approach looks like you want to do a dynamic skills list which automatically appends virtual objects to widen the range. Try dynamic creating with pointer (-> handle!!) connections. It is also recommended to write a new function to read/write skills, because the object with the skills is now relative (because there are now more than the original entity) which are possible to use.

I think until we have no pointers to variables I bet there are some serious users which have to do such a thing when they want some kind of local variables which could be accessed from outside!

(this is a wink, conitec )

ciao
christian

Last edited by HeelX; 10/07/05 14:20.
Re: Getting more than 100 skills without DLL [Re: HeelX] #57220
10/07/05 14:55
10/07/05 14:55
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
I placed execute() to avoid big case switch(100 cases) (if (Skillnum==1){retval=entity.skill1} else {if(...). About slow, If somone needs 200 skills, TRY IT and report FPS (script time)

Re: Getting more than 100 skills without DLL [Re: Lion_Ts] #57221
10/07/05 15:17
10/07/05 15:17
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
I bet, when you write a in-itself structured if then else case decision tree, it is everytime faster than execute.

Last edited by HeelX; 10/07/05 15:17.
Re: Getting more than 100 skills without DLL [Re: HeelX] #57222
10/07/05 15:24
10/07/05 15:24
Joined: Mar 2003
Posts: 569
FRAJO Offline
User
FRAJO  Offline
User

Joined: Mar 2003
Posts: 569
function withoutifs(&firstskill,whatskill)
{
return firstskill[whatskill];//whatskill==skill you wnat to receive - 1
}

...
aSkill=withoutifs(my.skill1,5);
//aSkill is now filled with the 6th skill
...


------------------------------------------- ICQ: 242543712 Ich bin nicht hier und bin nicht da. Wo bin ich dann? ".." ("") ^ ^ This is the evil vampire bunny. Copy and paste him into your signiture to help him achieve world domination. Yeah
Re: Getting more than 100 skills without DLL [Re: Lion_Ts] #57223
10/07/05 16:11
10/07/05 16:11
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline
Expert
Rhuarc  Offline
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
It's a lot easier to use arrays....

example:
Code:

define SKILL_SLOT = skill99;
define EXTRA_SKILLS = 100;
define ENTITY_LIMIT = 100;
define SKILLARRAYSIZE = 10000; //EXTRA_SKILLS*ENTITY_LIMIT

var skills[SKILLARRAYSIZE];
var skillslots[ENTITY_LIMIT];

entity* tempSkillEnt;
function init_skills(ent)
{
tempSkillEnt = ent;
var i;
while(i<ENTITY_LIMIT)
{
if(!skillslots[i]){ tempSkillEnt.SKILL_SLOT = i; skillslots[i]=1; return(1); }
i+=1;
}
return(0); // no free slots!
}

function destroy_ent_skills(ent)
{
var i;
tempSkillEnt = ent;
skillslots[i]=1;
while(i<EXTRA_SKILLS)
{
skills[tempSkillEnt.SKILL_SLOT*EXTRA_SKILLS+i]=0;
i+=1;
}
tempSkillEnt.SKILL_SLOT = -1;
return(1);
}

// resets all skills (in event of level load!)
function destroy_all_skills()
{
var i;
while(i<ENTITY_LIMIT)
{
skillslots[i]=0;
i+=1;
}
while(i<SKILLARRAYSIZE)
{
skills[i]=0;
i+=1;
}
return(1);
}

function set_skill(ent,skillNum,value)
{
tempSkillEnt = ent;
if(tempSkillEnt.SKILL_SLOT==-1){return(0);}
skills[tempSkillEnt.SKILL_SLOT*EXTRA_SKILLS+skillNum]=value;
return(1);
}

function get_skill(ent,skillNum)
{
tempSkillEnt = ent;
if(tempSkillEnt.SKILL_SLOT==-1){return(0);}
return( skills[tempSkillEnt.SKILL_SLOT*EXTRA_SKILLS+skillNum] );
}



Example usage:
Code:

action my_extra_skills_entity
{
init_skills(my);
set_skill(my,50,100); //sets extra skill #50 to 100
get_skill(my,50); // returns 100
}



Untested, but should work.


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: Getting more than 100 skills without DLL [Re: Rhuarc] #57224
10/07/05 17:43
10/07/05 17:43

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Wow, thanks, I need more than a thousand skills for the animation capabilities I'm putting in my light/sound correlation program as I ran out of 100 skills quickly. Variables will not work locally when I'm dynamically creating many of them with the same function, they have a very small max local array count. Do you have the dll code? Thanks again! Your contributions are very helpful LionTs!

Re: Getting more than 100 skills without DLL [Re: ] #57225
10/07/05 21:44
10/07/05 21:44
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Thank you, espesially to RHUARC
Guys, you are creative, why didn't you post it ?

Re: Getting more than 100 skills without DLL [Re: FRAJO] #57226
10/08/05 09:38
10/08/05 09:38
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline OP
Serious User
Lion_Ts  Offline OP
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Frajo, good idea to cast skills as array. Thank you. I'll try to overwrite this 'slow' code.
@WING: I haven't DLL, but i'm thinking about it. When finished I'll post code and compiled DLL here.

Re: Getting more than 100 skills without DLL [Re: Lion_Ts] #57227
10/08/05 10:56
10/08/05 10:56
Joined: Dec 2003
Posts: 266
Celle
task1 Offline
Member
task1  Offline
Member

Joined: Dec 2003
Posts: 266
Celle
thanx.itīs very helpfuly


visit my pages: www.xiron.de ICQ: 335016379 Messenger: lalimited@hotmail.com
Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1