Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/20/26 18:18
Ranger by Robert Pardo - now for Zorro
by Smallz. 06/20/26 11:23
Z12 live performance
by jcl. 06/19/26 11:21
Z9 getting Error 058
by jcl. 06/16/26 09:51
How to select between IB accounts by script?
by AndrewAMD. 06/13/26 15:44
Zorro tutorial ideas?
by AndrewAMD. 06/13/26 15:01
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (Grant, TipmyPip), 4,595 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Student_64151, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Assigning multiple handles #340520
09/04/10 22:59
09/04/10 22:59
Joined: Feb 2007
Posts: 146
UK
robertbruce Offline OP
Member
robertbruce  Offline OP
Member

Joined: Feb 2007
Posts: 146
UK
Hello,

I am using a global variable to call entities using handles.


//////////////////////////////////////////////////////////////

function call_entity
{

temp_ptr = ptr_for_handle(my_entity[my.skill1]);

}


action call_ent_action
{
call_entity();
//code
}



action level_entity
{

my_entity[entity_index] = handle (my);
entity_index+= 1;
//rest of code
}





Is there a way of keeping this local? ie not using a global entity pointer? One way would be to use different entity pointers such as:

entity* temp_ptr1;
entity* temp_ptr2;
entity* temp_ptr3;
entity* temp_ptr4;
entity* temp_ptr5


So I could use

function call_entity
{

temp_ptr = ptr_for_handle(my_entity[my.skill1]);
temp_ptr2 = ptr_for_handle(my_entity[my.skill1]);
temp_ptr3 = ptr_for_handle(my_entity[my.skill1]);

}

//////////////////////////////////////////////////////////////


This is fine but I may need to use large numbers of handles to call the my_entity array.


what I would like to be able to do is use :

my.skill2 = ptr_for_handle(my_entity[my.skill1]);

but this obviously won't work. So is there another way of setting a unique ID locally?


Any help would be appreciated.

Rob

Re: Assigning multiple handles [Re: robertbruce] #340681
09/06/10 15:52
09/06/10 15:52
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Do you need multiple handles or multiple pointers? (That's a difference, you know? wink )

Re: Assigning multiple handles [Re: Pappenheimer] #340742
09/07/10 12:55
09/07/10 12:55
Joined: Feb 2007
Posts: 146
UK
robertbruce Offline OP
Member
robertbruce  Offline OP
Member

Joined: Feb 2007
Posts: 146
UK
Thanks for the reply.

Pointers I believe.



I have made an example which hopefully makes things clearer.



///////////////////////////////////////////////////////////////
entity* temp_ptr1;
entity* temp_ptr2;
entity* temp_ptr3;



//10 of these are placed in WED
action marker
{
my_entity[entity_index] = handle (my);
entity_index+= 1;
}



function check_distance1
{
if (vec_dist (temp_ptr.x, my.x) < 500){temp_ptr.light=on;temp_ptr_lightrange=0;}
}


function check_distance2
{
if (vec_dist (temp_ptr2.x, my.x) < 500){temp_ptr.light=on;temp_ptr_lightrange=0;}
}


function check_distance3
{
if (vec_dist (temp_ptr3.x, my.x) < 500){temp_ptr.light=on;temp_ptr_lightrange=0;}
}



//1st entity
action test_subject
{
my.skill1=1;
temp_ptr = ptr_for_handle(my_entity[my.skill1]);
check_distance1();
//movement code here
}

//2nd entity
action test_subject2
{
my.skill1=2;
temp_ptr2 = ptr_for_handle(my_entity[my.skill1]);
check_distance2();
//movement code here

}

//3rd entity
action test_subject2
{
my.skill1=3;
temp_ptr3 = ptr_for_handle(my_entity[my.skill1]);
check_distance3();
//movement code here

}



If we have 3 entities (test_subjects) that move around to check distances with 10 markers I have to use different pointer for each test_subject entity to be able to identify the correct marker.

Instead of using 3 test_subjects which use a unique pointer is there a way to use just one test_subject with a unique ID (any skill) which checks a marker that is the same as it's skill1 value.



function check_distance1
{
if (vec_dist (temp_ptr.x, my.x) < 500){temp_ptr.light=on;temp_ptr_lightrange=0;}
}


action test_subject
{

my.skill1=3;
temp_ptr = ptr_for_handle(my_entity[my.skill1]);

check_distance();

//movement code here

}



Is there a way to store the pointer to the entity for each test subject? Otherwise the pointer keeps changing everytime the temp_ptr value is changed and I have to use a different pointer for each entity (test_subject).


Hope this makes sense.

Cheers,

Rob

Re: Assigning multiple handles [Re: robertbruce] #340820
09/07/10 20:04
09/07/10 20:04
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
I guess that your main question is this:
"is there a way to use just one test_subject with a unique ID (any skill) which checks a marker that is the same as it's skill1 value"?

The following is one of my ways doing such stuff. It is not tested (I always forget how to define a skill), but I hope you understand the system.

var number_of_marker = 0;
var number_of_test_subject = 0;

#define id skill1
#define marker 1
#define test_subject 2

#define group skill2

#define marker_handle skill3

function check_distance()
{
if (vec_dist (you.x, my.x) < 500)
{you.light=on;you.lightrange=0;}
}

action marker_act()
{
my.id = marker;
my.group = number_of_marker;
number_of_marker += 1;//count up a global variable to give each marker a unique number
}

action test_subject_act()
{
my.id = test_subject;
my.group = number_of_test_subject;
number_of_test_subject += 1;
wait(1);//wait the first frame cycle, because every entity should have its number
you = ent_next(NULL);//check each entity to find the 'personal' marker
while(you)
{
if((you.id == marker)&&(you.group == my.group))
{my.marker_handle == handle(you);}
you = ent_next(you);
}
while(1)
{
you = ptr_for handle(my.marker_handle);
check_distance();
wait(1);
}
}

Re: Assigning multiple handles [Re: Pappenheimer] #340891
09/08/10 11:52
09/08/10 11:52
Joined: Feb 2007
Posts: 146
UK
robertbruce Offline OP
Member
robertbruce  Offline OP
Member

Joined: Feb 2007
Posts: 146
UK
Thanks for the code. It's made things alot clearer.

On a final note, is there an alternative to using you for the pointer since I keep getting an error (unidentified pointer) when tracing between the you and my positions.

you = ptr_for handle(my.marker_handle);

result=trace(my.pos,you.pos);
if(result>1){//rest of code}


But when using temp_ptr it works fine.

entity* temp_ptr;

temp_ptr = ptr_for handle(my.marker_handle);

result=trace(my.pos,temp_ptr.pos);
if(result>1){//rest of code}


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1