array in skill, is it possible?

Posted By: kholis

array in skill, is it possible? - 06/15/10 00:40

Code:
#define enemy_list[100], SKILL2;


i want my entity detect their enemies id. but it failed using that way.

any ideas?

thanks
Posted By: MMike

Re: array in skill, is it possible? - 06/15/10 00:58

i guess thats not possible at all.
I mean arrays must be defined globally,m the only way to define them local is with index of 3, (which is a vector)
but if you define enemy_list[100], skill2, your are "casting" the array to fit a variable, and you would lose the array index... so it makes no sense for me.

But there could be another answer to that....
Posted By: pararealist

Re: array in skill, is it possible? - 06/15/10 03:05

I wonder if something like this would work?
not tried:

var enemy_list[100];
var* listPtr = &enemy_list;

my.skill2 = &listPtr;

if (my.skill2[0] == whatever)
{
}
Posted By: HeelX

Re: array in skill, is it possible? - 06/15/10 04:48

Then why don't you try it? This would be my approach:

Code:
// Static

var array[100];
my.skill2 = array; // array is already var*!
(my.skill2)[5] = 6;
printf("(my.skill2)[5] = %f", (double)((my.skill2)[5])); // Test

// Dynamic

my.skill2 = sys_malloc(100 * sizeof(var)); // Create array
(my.skill2)[5] = 6;
printf("(my.skill2)[5] = %f", (double)((my.skill2)[5])); // Test



Also, "The editors" is the wrong forum for this... I move this thread.
Posted By: kholis

Re: array in skill, is it possible? - 06/15/10 05:27

@MMike & pararealist
thanks for reply..

@HeelX
looks you code make sense.

big thank to you laugh

..and really sorry for wrong forum. feel free to move it to the right place.

---
i've tried your code but had no luck. this is error message while compiling: "subscript require array or pointer type <(my.skill2)[0] = 6; >"

Posted By: DJBMASTER

Re: array in skill, is it possible? - 06/15/10 11:09

Remember that my.skill2[n] is the same as *(&my.skill2 + n)...
Code:
ent.skill2 = (var*)malloc(10 * sizeof(var)); 
*(&ent.skill2 + 2)  = 5; // set index 2 to value of 5


Posted By: kholis

Re: array in skill, is it possible? - 06/15/10 11:23

nice trick DJBMASTER.
but the index cannot change into variable

*(&ent.skill2 + 2) = 5; //works

but
n = 2;
*(&ent.skill2 + n) = 5; // not works

need help. thanks
Posted By: DJBMASTER

Re: array in skill, is it possible? - 06/15/10 11:38

huh? Works just fine for me...
Code:
int n = 2;

ent.skill2 = (var*)malloc(10 * sizeof(var)); 
*((&ent.skill2) + n) = 5;
	
error(str_for_num(NULL,(*(&ent.skill2 + n))));


Posted By: kholis

Re: array in skill, is it possible? - 06/15/10 12:26

ahh.. my mistake. i declare var n instead of int n grin

thanks DJBMASTER
Posted By: pararealist

Re: array in skill, is it possible? - 06/15/10 13:08

@ Helix
Quote:
Edited by pararealist (Today at 04:05 AM)

was just going to bed.
Posted By: Slin

Re: array in skill, is it possible? - 06/15/10 14:24

This should do the job, in case the previous examples didnīt:
Code:
my.skill2 = (var)sys_malloc(100*sizeof(var)); // Create array
((var*)my.skill2)[5] = 6;
printf("((var*)my.skill2)[5] = %f", (double)((var*)my.skill2)[5]); // Test


Posted By: Locoweed

Re: array in skill, is it possible? - 06/18/10 04:36

I always use like skill1 for EntityNum, a specific unique ID when that entity is created, after that, you can use that EntityNum to do what ever you want.

I create a structure, I usually call it like Skills and just make it array size of Max entities I will ever have in game, and can free up EntityNum's when units are killed, etc. But using a unique EntityNum you can basically created as many skills and types as you like in a structure format. I realize its not pretty, but very effective.

Example:

#define MAX_ENTITIES 50000

typedef struct _SKILLS
{
ENTITY* pEnemy[100];

// just some examples stuff of variable types you can add to Skills structure
ENTITY* pWeapon; // pointer to unit's weapon
var FlyByHeight;
var CruiseHeight;
var LastWingAngTiltAdj;
var bCanStrafe;
var aircraftStallRoll;
var HoverAngle;
ANGLE vHoverAngle; // hovering anjust angle to make sway while hovering
var bTakingOff; // aircraft taking off?
var bLanding; // aircraft landing?
var DistanceToGround; // current distance to ground
var bTracedTerrain; // was terrain traced when checking distance to ground?
VECTOR vTerrainNormal; // what was the normal of the terrain on the trace to ground


} SKILLS;

static SKILLS Skills[MAX_ENTITIES]; // Skills structure


So after this you can basically have infinite skills of any variable type you like (including arrays).

Now to set pointer to first enemy in list you just:

Skills[my.EntityNum].pEnemy[0] = you;

To retrieve a entitiy # x from enemy list you:

ENTITY* pEnt;
x = 50; // let's get my enemy # 50
pEnt = Skills[my.EntityNum].pEnemy[x];

Simple and effective way to basically create more skills of whatever variable type you want (and can make arrays inside the structure), as long as you give each Entity it's own unique EntityNum.

In a games like the one I am working on where we exhausted the 100 skills long ago per entity, creating a unique ID for each entity and then using a structure, especailly with arrays is a godsend. With our multiplayer game we general save the actual 3DGS Skills for variables being sent over multiplayer, and put local skills into the structure skills.

Later,
Loco
Posted By: Joey

Re: array in skill, is it possible? - 06/18/10 11:32

yeah, it's people like you who write browsers that take up half a gig of ram wink. no, honestly, that's a waste of memory, isn't it?
Posted By: Locoweed

Re: array in skill, is it possible? - 06/19/10 02:09

It's not the 1980's like when your 64k of memory had to be used to the extreme. Yes, it waste some memory, but with today's machines, its not as big as deal as you are making it out to be.

But, if you are very anal about memory useage, by all means, don't use that method.

It's just a possible method, and of course, most games will never have like 50000 entities either. Probably more like 500 entities in game at once at most. If you want to worry about memory more than functionality, be my guest.

I can also go back and write games in machine langauge again also like the old days, but I prefer to use higher languages now, even though machine language is much more efficient.

I know, post is worthless without pics. wink
Posted By: Locoweed

Re: array in skill, is it possible? - 06/19/10 05:34

You have really rubbed me the wrong way Joey. Forum entique would say you don't get attitude with people that have been on forum longer than you. All you had to say was, doesn't that waste memory? But you had to say before that, "it's people like you who write browsers that take up half gig of ram".

So, bite me.

I was going to write "Bite me" in chat of game, but to condense time, I ran game in single player with enemies at close range.
Posted By: Locoweed

Re: array in skill, is it possible? - 06/19/10 05:55

So whenever you are involved with a game like I am, you can clown me, until then, shut the frack up and don't disrepect me.

Just say, "Doesn't that waste memory," not "it's people like you who write browsers that take up half a gig of ram."

Don't be expecting our company to be calling you for cover art, lol.

I put video up in single player mode, with enemies at front door, to keep video size down. Also reduced video size to make video smaller.

And yeah, we have SpeedTree and SpeedGrass in game also, just not in this example.

Until the time you are working on a project like where this one is at, please, don't disrepect me again dude. I really don't appreciate that.

Although you did manage to get a video up with 1/20th of game play. And no one will ever see it.

http://www.darkdawnstudios.com/3DGS/GameWastingMemory.avi


Love ya, Seriously, "Bite me".
Posted By: Joey

Re: array in skill, is it possible? - 06/19/10 08:46

is it possible that you may have overseen the ;)-smiley? and the "no, honestly" part? that means that the first part was a joke, okay?
Posted By: Locoweed

Re: array in skill, is it possible? - 06/19/10 10:58

It's my bad Joey, I get irritated easily anymore, maybe take things to seriously, thus why I never post anymore. Sorry that I went off. Just been one of those days and the first sentence set me off for some reason.
Posted By: Pappenheimer

Re: array in skill, is it possible? - 08/21/10 17:14

Sorry for digging up an old thread.
Is it possible to make a define of those array 'positions'?
For instance:
#define ((var*)my.skill2)[0] speed_rel
#define ((var*)my.skill2)[1] speed_abs
#define ((var*)my.skill2)[2] fall_speed
...
and write instead
((var*)my.skill2)[2] = 6;
this
fall_speed = 6;

Originally Posted By: Slin
This should do the job, in case the previous examples didnīt:
Code:
my.skill2 = (var)sys_malloc(100*sizeof(var)); // Create array
((var*)my.skill2)[5] = 6;
printf("((var*)my.skill2)[5] = %f", (double)((var*)my.skill2)[5]); // Test


Posted By: Saturnus

Re: array in skill, is it possible? - 08/21/10 20:01

Sure, you can do this.

However, it should read
#define fall_speed ((var*)my.skill2)[2]
instead of
#define ((var*)my.skill2)[2] fall_speed
(etc).

It's not very flexible that way, though, as it requires the my pointer.

This is probably somewhat more convenient:
#define fall_speed(ent) ((var*)(ent)->skill2)[2]
...
fall_speed(my) = 56;

Posted By: Pappenheimer

Re: array in skill, is it possible? - 08/21/10 20:16

In thew first case I have to write
my.fall_speed = 56;
instead of
fall_speed(my) = 56;
- right?
Posted By: Saturnus

Re: array in skill, is it possible? - 08/21/10 21:41

No, in the first case (#define fall_speed ((var*)my.skill2)[2]) you'd have to write it like that :
fall_speed = 56; (without my)
as fall_speed gets replaced with ((var*)my.skill2)[2]. So this macro doesn't work with other entity pointers than my.

That's why I suggested the other method, where you can pass the entity pointer.
Posted By: Pappenheimer

Re: array in skill, is it possible? - 08/21/10 22:14

Ah, okay. Great. Thank you! laugh
© 2024 lite-C Forums