|
how to pass pointers using event functions
#349469
12/07/10 22:01
12/07/10 22:01
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
Hi everybody, I have the folloing problem: There is no possiblity to pass pointers, references, parametes unsing the event function. My objective is the following: removing an Entity (a local one!) when hitting an other entity! example
void ent_1(ENTITY* temp)
{
c_move (temp, ...);
temp.emask = ENABLE_ENTITY;
temp.event = remove_temp;//here is the problem: no parameter can be passed
}
void remove_temp (HERE NO PARAMENTER POSSIBLE)
{
ent_remove (THE temp POINTER is invalid here);
}
Last edited by MPQ; 12/07/10 22:33.
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: how to pass pointers using event functions
[Re: Superku]
#349473
12/07/10 22:31
12/07/10 22:31
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
ok i ll try out: ok it looks like that the me pointer is automatically passed, thank you superku. But an other problem arises: When the entity is removed, the local entity of the calling function becomes invalid, what to do
void remove_temp()
{
wait(1);
ent_remove(me);//now the temp pointer of the calling function becomes invalid
}
void ent_1(ENTITY* temp)
{
temp.emask = ENABLE_ENTITY;
temp.event = remove_temp;//here is the problem: no parameter can be passed
while(1)//while(temp)
{
c_move (temp, ...);//temp becomes invalid when it is removed, invalid pointer error
wait(1);
}
}
no idea?
Last edited by MPQ; 12/09/10 09:35.
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: how to pass pointers using event functions
[Re: MPQ]
#351399
12/24/10 10:50
12/24/10 10:50
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
thanx with the pattern of txsmi it works pretty well, the code looks like that:
int remove_temp()
{
return (my.skill1 = 1);
}
void ent_move(ENTITY *temp)
{
temp.emask = ENABLE_ENTITY;
temp.event = remove_temp;
while(!temp.skill1)
{
c_move (temp, ...);
wait(1);
}
ent_remove(temp);
}
void create_ent()
{
ENTITY *temp1;
temp1 = ent_create (...);
ent_move (temp1);
}
Ok, the handing over of pointers works quite well so far, but why does lite-c not support references, I thought it would be more like C++ and supports this feature, but here it look more like C. Does lite-c support Classes?
Last edited by MPQ; 12/24/10 13:48.
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
|