ent_next

Posted By: Martek

ent_next - 01/27/08 18:56

hi,

ich möchte prüfen ob irgend ein entity den skill squad größer als 1 hat.
Dazu habe ich folgene funktion geschreiben, aber ich bekomme immer als fehler meldung, das der pointer you leer ist. Wo liegt dabei der fehler???
Code:
function show_squads()
{
var i = 1;
var counter1;
you = ent_next(null);

while(1)
{
if(i == 1)
{
if(you.squad == 1)
{
counter1 += 1;
}

you = ent_next(you);

if(you == null)
{
if(counter1 != 0)
{
squad1_pan.visible = on;
}
else
{
squad1_pan.visible = off;
}

i = 0; //reset var
counter1 = 0; //reset var
}
}

if(i == 0)
{
you = ent_next(null);
i = 1;
}

wait(1);
}
}



Mfg, Pingulord
Posted By: Helghast

Re: ent_next - 01/28/08 08:11

ok, im gonna reply in english, my german isnt the best, but i can read it
I think what happens here, it goes through the loop normally. and comes to a point where you = null. then you set i to 0, and it quits the if that reads i == 1.
it comes in the other branch, and continues the ent_next, even though it was empty.
I think what you need there is simply: you = null;

that's what came to mind when reading through it real quick.
anyway, worth a try!

regards,
Posted By: Martek

Re: ent_next - 01/28/08 12:56

Thanks for your answer, but I can't imagine where I should place the you = null;
If it would help you, this is the problem. I copyed it out of the acklog.txt:

Empty pointer in show_squads: (you.squad==1) - any key to abort

Mfg, Pingulord
Posted By: Martek

Re: ent_next - 02/06/08 18:03

Does nobody know where I must place the you = null; ???
Plesa help.

Mfg, Martek
Posted By: Gordon_Shumway

Re: ent_next - 02/06/08 19:28

Hi,
probier das mal:
function show_squads()
{
var counter1=0;
you = null;
you = ent_next(NULL); // you auf erste Entity setzen (Sprung von Null auf 1. Entity)
while (you!=NULL)
{
if(you.squad == 1)
{
counter1 += 1;
}

you = ent_next(you);
continue;
}
}
Jetzt werden alle Entities durchgegangen und immer wenn eine Entity den skill squad == 1 hat, wird counter1 um eins erhöht.
Ich denke, dass sollte dir helfen, oder?
Bye G.S.
Posted By: Martek

Re: ent_next - 02/07/08 13:36

Vielen Dank,
ich musste es zwar noch etwas abändern, aber es funktioniert jetzt.

Mfg, Martek
© 2024 lite-C Forums