skills and local variables treated as global

Posted By: Nowherebrain

skills and local variables treated as global - 04/27/08 14:20

sorry for double posting(I origionaly posted this in a thred dedicated to something else)
I'm having another pointer issue.
__________________________________
4 entitys share the same action.

In a separate function I set one to speaker(pointer) and the rest to non_speaker(again, pointer)by testing their vec_dist to the player.

if I set speaker.skill1 to any number, all the ents with the same action get the same value for skill1...regardless of their pointer
___________________________________

Is this a bug or am I doing something wrong here, have pointers changed(how)...under lite-c?
skill1 is being treated like a global variable here, I noticed it states something like this in the manual. Does anyone know a workaround/method?
Posted By: Excessus

Re: skills and local variables treated as global - 04/27/08 15:42

Sounds like your pointers are just pointing to the same thing (even though you may think they're not). Could you post your code?
Posted By: Nowherebrain

Re: skills and local variables treated as global - 04/27/08 16:02

it almost literaly looks like this..

ENTITY* speaker;
ENTITY* non_speaker;

function dialogue_pointer()
{
if(vec_dist(player.x,my.x) < 100)
{
speaker = me;
{
else
{
non_speaker = me;
}
}

action actor()
{
while(player != NULL)
{
dialogue_pointer();
if((my.skill1 == 1) && (speaker == me))//no need to test dist already tested
{
init_dialogue();
my.skill1 = 0;//this however sets all "actors" skill1 to 0.
}
wait(1);
}
}

sorry for the stripped down version, but no one likes to sift through a thousnd lines of unrelated code. this is the only place where skill1 is even looked at or modified...very basic stuff, probably the reason it is killing me.
Posted By: Nowherebrain

Re: skills and local variables treated as global - 04/27/08 16:03

should I be using...

set(me,speaker);

I also use a material(just ambient change) change here and it works???
Posted By: Uhrwerk

Re: skills and local variables treated as global - 04/27/08 21:54

Yes, you should, if you really want to mess it up... ;\) Honestly, set is a macro designed for easily setting flags of an entity. Don't use it on pointers.

One thing caught my eye: You said there were three entities non-speakers and on speaker. Your code doesn't represent this. You just check the distance and assign a pointer corresponding to the distance. As you only defined two pointers only the last two entites checked will be pointed to anyways. If you're lucky and the distance of one is > 100 and the other ones is < 100 then you will have to pointers, one pointing to an entity farer away, the other one pointing to the nearer one. If you're not so lucky the distance will be < 100 or < 100 for all entites and only one pointer will get assigned at all.

Keep in mind a pointer can only point to one certain address and will not be able to point to a group of entities.
Posted By: Nowherebrain

Re: skills and local variables treated as global - 04/28/08 00:17

ahh, ok...maybe just assigning speaker will do the trick. Thanks for the advice I will test it soon...switched over to the art side for a bit..seeing as I was stuck.
Posted By: Nowherebrain

Re: skills and local variables treated as global - 04/28/08 12:08

yep...sorta, I had to set up a switch sorta, bool, but it works efficiently..thanks.
Posted By: Nowherebrain

Re: skills and local variables treated as global - 04/29/08 00:57

OK, I was wrong...dead wrong.
if you are setting my.skillx, it sets them all..
instead use pointerstring.skill1, this will only affect the pointer...Doh!
This is not the place, but maybe this should be added to "beginners mistakes" in the manual. ???
Posted By: Uhrwerk

Re: skills and local variables treated as global - 04/29/08 16:19

 Originally Posted By: Nowherebrain
if you are setting my.skillx, it sets them all..
instead use pointerstring.skill1, this will only affect the pointer.

That's not the whole truth. my.skillx = y will only set one entities skillx to y. But you have to keep in mind, that there may be multiple instances of a function running, with their me pointers pointing to different entities.
Posted By: Nowherebrain

Re: skills and local variables treated as global - 04/30/08 01:30

but there is always the possibility if you have many ents with the same action....but c_move is a perfect example of you philosophy, in that instance I use the typical "my" with no issues...
© 2024 lite-C Forums