|
3 registered members (AndrewAMD, Grant, Neb),
908
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Handles
#176119
01/03/08 00:04
01/03/08 00:04
|
Joined: Feb 2002
Posts: 357 Florida
Zelek
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2002
Posts: 357
Florida
|
I am having some trouble with handles. The manual says: Quote:
A handle is a unique object number that can be assigned to any variable, and identifies that object.
However, when I test this, I get the same handle for multiple entities (ie, not unique). Here's how I'm testing:
Code:
if(key_q) { //create a blank entity with no action test_ent = ent_create (null, vector (0,0,0), NULL); wait(-.5); //only necessary for multiplayer handle_var = handle(test_ent); //store the ent handle num_ents = num_ents+1; //keep count of # of ents }
I have a debug panel that shows me handle_var and num_ents. Every time I hit q, I can see that new entities are being created, but the handle stays the same. What's going on?
The handle is always 65536, which is suspiciously also the range of a short. Am I not even getting a valid handle?
|
|
|
Re: Handles
[Re: Zelek]
#176120
01/03/08 09:53
01/03/08 09:53
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
if(key_q) { //create a blank entity with no action test_ent = ent_create (null, vector (0,0,0), NULL); wait(-.5); //only necessary for multiplayer handle_var[num_ents] = test_ent; //store the ent handle num_ents += 1; //keep count of # of ents}
if(key_q) { //create a blank entity with no action handle_var[num_ents] = ent_create (null, vector (0,0,0), NULL); num_ents += 1; //keep count of # of ents wait(-.5); //only necessary for multiplayer }
dint test it but could loolk likte this
"empty"
|
|
|
Re: Handles
[Re: flits]
#176121
01/04/08 01:51
01/04/08 01:51
|
Joined: Feb 2002
Posts: 357 Florida
Zelek
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2002
Posts: 357
Florida
|
So you assign the pointer directly to the variable, without ever calling the handle() function? Why does the manual show the following example: Code:
my.skill48 = handle(entity);
Isn't "entity" a pointer in this example?
|
|
|
Re: Handles
[Re: Zelek]
#176122
01/04/08 03:06
01/04/08 03:06
|
Joined: Jun 2006
Posts: 214 Germany, NRW
TheThinker
Member
|
Member
Joined: Jun 2006
Posts: 214
Germany, NRW
|
Hi, Your example runs without problems. I think the only problem is the debugging function you are using. Only three fractional numbers are shown by str_for_num. The rest is truncicated (oh what a word - perhaps wrong). I used this to show the changing handles: str_for_num(debug1,fraction(handle_var) * 1000); So you can see that handle_var changes. I tested it. If it don't work ask  MfG Patrick
|
|
|
Re: Handles
[Re: TheThinker]
#176123
01/04/08 03:15
01/04/08 03:15
|
Joined: Mar 2003
Posts: 4,264 Wellington
Nems

.
|

.
Joined: Mar 2003
Posts: 4,264
Wellington
|
Here's a little something from 'The Master', AUM 47.
Handles
What do you do when you need to control 20 different entities? Well, you can define 20 different pointers named (let's say) tree1... tree20 and maybe change their z positions this way: tree4.z = 200; or tree15.z = 150; and so on. But what do you do if you need to control 100 or 1000 entities? Who wants to define 1000 pointers?
This small article will show you how to use handles, which are nothing more than unique numbers that can be associated to any of your entities, actions, strings, bitmaps, panels... (almost) whatever you might need.
var index = 0; var my_entities[100]; // control up to 100 different entities
entity* temp_ptr; // temporary pointer to the entity
I have defined a variable named index and an array that can store up to 100 handles; I chose 100 as an example, but you can control over 10,000 entities without any problem. I have also defined a temporary pointer named temp_ptr.
action control_entities { my_entities[index] = handle (my); index += 1; // put the rest of your entity code here }
The action above is attached to our entities; it stores the handle to the entity (a number) inside the array, at the position given by the index variable, and then it increments index, allowing the other entities to store their handles inside the array.
function move_entity(number, height) { temp_ptr = ptr_for_handle(my_entities[number]); temp_ptr.z += height; // increase the z of the entity by "height" quants }
This is a simple example of a function that moves an entity along its z axis; you could use it to move the crowd sprites in your sports game, and so on. Call the function this way:
move_entity(5, 40);
and it will move the 5th entity 40 quants upwards; or call it this way:
move_entity(23, -30);
and it will move the 23rd entity downwards by 30 quants. If you use a while loop to generate random numbers and heights, and then you call function move_entity using those values, you will have a realistic looking, furiously animated crowd in no time!
|
|
|
Re: Handles
[Re: Nems]
#176124
01/04/08 15:53
01/04/08 15:53
|
Joined: Aug 2005
Posts: 1,558 HK
vlau
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,558
HK
|
Quote:
The handle is the first integer of an object. It consists of a unique index number plus an object type identifier taken from the following table, and left shifted by 24. For converting the handle to a var that contains the index number, right shift it by 24, then left shift the resulting int by 10.
Quoted from the manual too. I think there's some magic behind the number. You may convert it using ptr_for_handle(handle).
var handle_var; handle_var = handle(test_ent); handle_var = ptr_for_handle(handle_var);
|
|
|
Re: Handles
[Re: TheThinker]
#176125
01/05/08 00:35
01/05/08 00:35
|
Joined: Feb 2002
Posts: 357 Florida
Zelek
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2002
Posts: 357
Florida
|
Quote:
Hi, Your example runs without problems. I think the only problem is the debugging function you are using. Only three fractional numbers are shown by str_for_num. The rest is truncicated (oh what a word - perhaps wrong). I used this to show the changing handles: str_for_num(debug1,fraction(handle_var) * 1000);
I think this is in fact my problem. I was trying to display the handles using the digits function in a panel, which is apparently incapable of displaying handles. Instead it just displays 65536 (how misleading and confusing). I'm still getting some weird behavior, but I think I can figure it out now that I can actually differentiate between handles.
Thanks to each of you for your help.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|