Empty Pointer woes

Posted By: JazzDude

Empty Pointer woes - 04/05/08 06:21

I've been trying to solve this all day with no luck. I hope someone can give me some help.

These two generator actions work fine by themselves. But when used together in the same level the trapper generator comes up with an empty pointer on "you.spawned_entity = on;"

If I put the trapper generator first, it works and the indian generator has the error.

code:
--------------------------------------------------------------------------
action indian_generator
{

while(1)
{
my.invisible = on;
my.passable = on;
temp.x = my.x +30;
temp.y = my.y + 30;
temp.z = my.z;
wait(2);
you = ent_create("warrior.mdl",temp,act_warrior);
you.spawned_entity = on; //triggers stuff in the warrior action
you.entity_type_id = indian_type; //triggers unique animations

wait(-5);
}
}

action trapper_generator
{
while(1)
{
my.invisible = on;
my.passable = on;
temp.x = my.x +30;
temp.y = my.y + 30;
temp.z = my.z;
wait(2);
you = ent_create("trapper.mdl",temp,act_trapper);
you.spawned_entity = on;
you.entity_type_id = trapper_type;

wait(-15);
}
}
--------------------------------------------------------------------------

(How do we quote code in this new format??)

I've used while(!you){wait(1);} in all possible places...and a hundred other things.

Any suggestions would be greatly appreciated. Thanks
Posted By: flits

Re: Empty Pointer woes - 04/05/08 07:50

i dont think this will work but you can try

make a ENTITY* ent_h;

ent_h = ent_create("warrior.mdl",temp,act_warrior);
ent_h.spawned_entity = on; //triggers stuff in the warrior action
ent_h.entity_type_id = indian_type; //triggers unique animations

if you wait a frame you could lose your you pointer

no other stupid sugestions yet (;
Posted By: A.Russell

Re: Empty Pointer woes - 04/05/08 08:05

Yes, you can change its value. Also, to protext yourself against empty pointers:

if(pointer == null)
return;

or if you are sure it will be created, but bot sure of the order:

while(pointer == null)
wait(1);

Also, look in using a "handle." Handles are a class that wrap pointers and manage them for you.
Posted By: JazzDude

Re: Empty Pointer woes - 04/05/08 17:45

Those three ideas failed, but thank you for making me look in some other directions.

I'm an idiot. I spend hours trying to find a complex solution to a simple problem.

The only problem with the two actions was using quotes ("trapper.mdl") instead of making and using a string (string trapper_model = <trapper.mdl>;)

So why did it work when the action was first? Beats me.
Why does it make a difference in this case? Beats me.

But next time I will check the radiator cap before I replace the water pump.
Posted By: Uhrwerk

Re: Empty Pointer woes - 04/05/08 18:02

Three remarks on your code, JazzDude:

1. Setting invisible and passable in a loop is senseless. Better place that before the loop. Increases performance... ;\)
2. Setting up the temp vector and then waiting 2 frames and finally using it is a source for hard to find errors. If you set up temp to vertain values you should use them immediately. Otherwise other functions may overwirte you temp vector with arbitrary data.
3. Be sure to wait at least one frame in your act_trapper and act_indian action, before reading out spawned_entity and entity_type_id.
Posted By: JazzDude

Re: Empty Pointer woes - 04/05/08 19:18

As you've noticed in the past, Uhrwerk, I don't use C-script.
I use Klutz-script, so constructive criticism is always very welcome.

\:\) Thanks.
Posted By: Uhrwerk

Re: Empty Pointer woes - 04/05/08 21:37

That's what we all use, JazzDude. It's just a question of stamina. The longer you do it, the more complex bugs you'll produce. ;\)
Posted By: vlau

Re: Empty Pointer woes - 04/06/08 07:28

I don't have any problem when running your script, maybe
the problem is somewhere else in "act_warrior" or
"act_trapper".
© 2024 lite-C Forums