1 registered members (AndrewAMD),
678
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Problems with pointers [new title]
#335723
07/30/10 11:09
07/30/10 11:09
|
Joined: Jul 2010
Posts: 127 Germany, Herford
Ditje
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 127
Germany, Herford
|
When I try to shoot my enemies, I use ent_remove(you). But if I hit the target, I (players ship) got removed not the hidden target
function move_bomb()
{
c_setminmax(me); // bounding box setzten
my.STATE = 1;
my.pan = your.pan;
my.tilt = your.tilt;
my.roll = your.roll;
while(1)
{
// Bombe flieg
if (my.STATE == 1)
{
c_move(me, vector(0, 50 * time_step, 0), vector(0, 0, 0), IGNORE_YOU);
if(my.y >= 980 || my.z >= 580)
{ // levelende erreicht?
my.STATE = 2;
}
if (HIT_TARGET)
{
//ent_create("explosion+4.bmp",vector(my.x,my.y,my.z+20),NULL); // particle effect planned
ent_remove(you);
my.STATE = 2;
}
}
// Bombe verschwinde
if (my.STATE == 2)
{
ent_remove(me);
bomb_anzahl --;
return; // !!! prevents further access to removed entity
}
wait(1);
}
}
an this is the player action, from where function move_bomb is called:
action spieler_aktion()
{
spieler = my;
my.STATE = 1;
while(1)
{
// auf und ab drehen
...
code for ship controll
...
// Schiessen - code for fireing
if (my.STATE == 1) // kein Schuss
{
if(mouse_left) my.STATE = 2;
}
if(my.STATE == 2) // Schuss
{
if(last_bomb_x == 15) last_bomb_x = -15;
else last_bomb_x = 15;
if(bomb_anzahl < 4)
{
ent_create("bomb.mdl",vector(my.x+last_bomb_x,my.y+10,my.z),move_bomb);
bomb_anzahl ++;
}
my.STATE = 3;
}
if (my.STATE == 3)
{
if (!mouse_left) my.STATE = 1;
}
wait(1);
}
}
Cheers Ditje
Last edited by Ditje; 08/02/10 14:39.
|
|
|
Re: who is you? - :-D funny effect
[Re: Ditje]
#335757
07/30/10 13:32
07/30/10 13:32
|
Joined: Aug 2008
Posts: 482
bart_the_13th
Senior Member
|
Senior Member
Joined: Aug 2008
Posts: 482
|
try to avoid using ent_remove(me) inside a loop since it could mess your code and put it at the end of your code. Try this code to replace your move bomb
function move_bomb()
{
c_setminmax(me); // bounding box setzten
my.STATE = 1;
my.pan = your.pan;
my.tilt = your.tilt;
my.roll = your.roll;
while(my.STATE==1)
{
// Bombe flieg
c_move(me, vector(0, 50 * time_step, 0), vector(0, 0, 0), IGNORE_YOU);
if(my.y >= 980 || my.z >= 580)
{ // levelende erreicht?
my.STATE = 2;
}
if (HIT_TARGET || my.y >= 980 || my.z >= 580)
{
//ent_create("explosion+4.bmp",vector(my.x,my.y,my.z+20),NULL); // particle effect planned
my.STATE = 2;
if(HIT TARGET)
{
//do something here to the HIT_TARGET
}
}
wait(1);
}
ent_remove(me);
}
|
|
|
Re: who is you? - :-D funny effect
[Re: bart_the_13th]
#335766
07/30/10 13:41
07/30/10 13:41
|
Joined: Jul 2010
Posts: 127 Germany, Herford
Ditje
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 127
Germany, Herford
|
Ah looks nice. Thank you. I will try it on monday - SED is already closed. I have to prepare me for Open Air Cheers Ditje
|
|
|
Re: Problems with pointers [new title]
[Re: Ditje]
#336226
08/02/10 14:38
08/02/10 14:38
|
Joined: Jul 2010
Posts: 127 Germany, Herford
Ditje
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 127
Germany, Herford
|
Hi I figured out a little bit how to use pointers. But not everything. Below you find my code - not needed is deleted. 1.) I want to call a function instead of only remove enemy and have no idea how to do it. 2.) After I have shoot some enemies I get 2 error messages. Invalid argument and SYS crash in move_bomb(). I can "play" further. After some time I get Invalid argument at every hit. May be calling the function is already the solution. But I don`t know the reason for errors. Cheers Ditje
// enemy functions ///////////////////////////////////////
function start_level_type1()
{
...
// a loop creates 40+n enemies
enemy = ent_create("bee1.mdl", vector(50, 1000, 500), start_bee_wave1);
...
}
function start_bee_wave1
{
// moves the enemies until until they reach their temporary position
}
function attack_player
{
// not done yet - get called
// if a all enemies reached final posion
// or if an enemy got killed
// of if an enemy got back from attack to temporary postion
}
// bomb functions /////////////////////////////////////////
function move_bomb()
{
...
if (HIT_TARGET)
{
snd_play(snd_explode,100,0);
punkte_spieler += 30;
///!!!!!!! Here is my problem !!!!!!!!!! ///////////
ent_remove(enemy);
my.STATE = 3;
}
...
}
// player action (added in WED) ///////////////////////////
action spieler_aktion()
{
...
bomb = ent_create("bomb.mdl",vector(my.x+last_bomb_x,my.y+10,my.z),move_bomb);
...
}
Last edited by Ditje; 08/02/10 14:40.
|
|
|
Re: Problems with pointers [new title]
[Re: Ditje]
#336238
08/02/10 15:53
08/02/10 15:53
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Hi, using pointers in Lite-C is pretty easy. I assume you have worked through the Lite-C workshop. 1) You can call a function from anywhere. All you have to do is create a new function with the code you want to call, give it a useful name and call it.
void main()
{
beep(); // make the engine 'beep'.
}
The above code using a seperate function...
void CallBeep()
{
beep();
}
void main()
{
CallBeep();
}
This is a useless example but shows you that you can break any code in various functions. This is called modular programming. 2) The reason the 'ent_remove(enemy);' call crashes is because the 'enemy' pointer is NULL. Removing a NULL pointer results in a crash. Make sure that 'enemy' isn't being removed already.
|
|
|
Re: Problems with pointers [new title]
[Re: DJBMASTER]
#336240
08/02/10 16:23
08/02/10 16:23
|
Joined: Jul 2010
Posts: 127 Germany, Herford
Ditje
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 127
Germany, Herford
|
Simply calling a function is not my problem. But in this case. I have a HIT_TARGET event and my function adresses the hit target, how do I call the function and give the hit ENTITY as parameter?
I noticed already, that my problem must already earlier, when I creat my enemies:
enemy = ent_create("bee1.mdl", vector(-100, 800, 400), start_bee_wave5);
This is done in a loop - so "enemy" got overwritten every time and keeps the value of the last loop. That`s the reason why I get the errormessage only sometimes. Can I create ENTITIES in an array like this?
enemy[i] = ent_create("bee1.mdl", vector(-100, 800, 400), start_bee_wave5);
|
|
|
Re: Problems with pointers [new title]
[Re: TrackingKeks]
#336267
08/02/10 17:36
08/02/10 17:36
|
Joined: Jul 2010
Posts: 127 Germany, Herford
Ditje
OP
Member
|
OP
Member
Joined: Jul 2010
Posts: 127
Germany, Herford
|
hmmm in my case sadly not. Error Cannot convert POINTR to 'struct ENTITY' Edit again: There are 2 problems this is getting the hit TARGET but there is an additional problem decribed in the following post sorry for to much posts I still suppose, that I haven`t found the right (english) description for my problem. This must be absolute basic - I have a variable ammount of enemies created by ent_create - I have a variable ammount of bombs Any bomb can hit any enemy. If (HIT_TARGET), there are a lot of things to do: - remove bomb - remove enemy - count up score - play sound - particle effect So if I create functions which are called by if(HIT_TARGET) the functions have to know which ENTITIES (bomb OR enemy) depend on. Now I check (HIT_TARGET) on my bombs and try to ent_remove(enemy). functionname(enemy) should work, to. But it doesn`t. I am sure solution with an array of enemies is not the right solution. I supposed that I can call the TARGET by "you". But doesn`t work. (see above: players ENTITY is "you"). Very weird, because it got not HIT. So how do I get the information which enemy is HIT? German: Das HIT_TARGET treibt mich echt in den Wahnsinn. Habe ich das Problem einigermaßen verständlich beschrieben? Bis jetzt habe ich das Gefühl: NEIN Es muss doch ultra simpel sein, die getroffene ENTIY an (HIT_TARGET) zurück zu geben. Wozu sollte die Funktion sonst sein?
Last edited by Ditje; 08/02/10 18:37.
|
|
|
|