2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
array in skill, is it possible?
#328749
06/15/10 00:40
06/15/10 00:40
|
Joined: Mar 2009
Posts: 25
kholis
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 25
|
#define enemy_list[100], SKILL2;
i want my entity detect their enemies id. but it failed using that way. any ideas? thanks
|
|
|
Re: array in skill, is it possible?
[Re: MMike]
#328754
06/15/10 03:05
06/15/10 03:05
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
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) { }
Last edited by pararealist; 06/15/10 03:05.
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: array in skill, is it possible?
[Re: pararealist]
#328763
06/15/10 04:48
06/15/10 04:48
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Then why don't you try it? This would be my approach:
// 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.
|
|
|
Re: array in skill, is it possible?
[Re: HeelX]
#328766
06/15/10 05:27
06/15/10 05:27
|
Joined: Mar 2009
Posts: 25
kholis
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 25
|
@MMike & pararealist thanks for reply.. @HeelX looks you code make sense. big thank to you ..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; >"
Last edited by kholis; 06/15/10 09:29.
|
|
|
Re: array in skill, is it possible?
[Re: kholis]
#328788
06/15/10 11:09
06/15/10 11:09
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Remember that my.skill2[n] is the same as *(&my.skill2 + n)...
ent.skill2 = (var*)malloc(10 * sizeof(var));
*(&ent.skill2 + 2) = 5; // set index 2 to value of 5
Last edited by DJBMASTER; 06/15/10 11:12.
|
|
|
Re: array in skill, is it possible?
[Re: kholis]
#328791
06/15/10 11:38
06/15/10 11:38
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
huh? Works just fine for me...
int n = 2;
ent.skill2 = (var*)malloc(10 * sizeof(var));
*((&ent.skill2) + n) = 5;
error(str_for_num(NULL,(*(&ent.skill2 + n))));
Last edited by DJBMASTER; 06/15/10 11:41.
|
|
|
Re: array in skill, is it possible?
[Re: DJBMASTER]
#328799
06/15/10 12:26
06/15/10 12:26
|
Joined: Mar 2009
Posts: 25
kholis
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 25
|
ahh.. my mistake. i declare var n instead of int n thanks DJBMASTER
|
|
|
|