Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
How can I set the entity name in script? #224447
08/30/08 07:26
08/30/08 07:26
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hi everybody,

when I set an entity in WED it gets a name by WED.

How can I set this entity name when I create the entity in script by ent_create ???

I tried it as follows:

player1 = ent_create (str_create("giana.mdl"), vector(489 , -71 , -150), NULL);
wait(1);
player1.link.name = "giana.mdl_02";

That causes no compiler problem at all, but doesn't set the name either :-(

Regards,
Pegamode.

Last edited by pegamode; 08/30/08 07:48. Reason: additional info
Re: How can I set the entity name in script? [Re: pegamode] #224451
08/30/08 10:18
08/30/08 10:18
Joined: Jun 2005
Posts: 87
France
MadJack Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
What about :

player1.name = "giana.mdl_02";

Or maybe:

str_cpy(player1.name ,"giana.mdl_02");


Commercial A7.25b
RUGod
Re: How can I set the entity name in script? [Re: MadJack] #224454
08/30/08 10:49
08/30/08 10:49
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I tried both already ... with no success:

both result in : name is not a member of ENTITY

I also tried:

str_cpy(player1.link.name,"giana.mdl_02");

compiles, but doesn't set entity's name.

Re: How can I set the entity name in script? [Re: pegamode] #224495
08/30/08 14:25
08/30/08 14:25
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Errr, whats wrong with calling it by the name you created
it under, as in "player1" from your examples?

Where is there a diffeerence?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How can I set the entity name in script? [Re: EvilSOB] #224500
08/30/08 14:45
08/30/08 14:45
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
If an entity is set in WED and you call (entity->link).name the name is returned.

If an entity is created by ent_create and you call the same NULL is returned.

So an entity created by ent_create has no name ...

Re: How can I set the entity name in script? [Re: pegamode] #224507
08/30/08 15:43
08/30/08 15:43
Joined: Aug 2008
Posts: 408
mi usa
sadsack Offline
Senior Member
sadsack  Offline
Senior Member

Joined: Aug 2008
Posts: 408
mi usa
It should have an entity number.


I have A7 Commercial .............. Now I just need to learn how to use it

Re: How can I set the entity name in script? [Re: sadsack] #224551
08/30/08 20:33
08/30/08 20:33
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
As a workaround I'm currently using entity.type which works fine enough in my case ... but I would prefer to set the entity's name.

Re: How can I set the entity name in script? [Re: pegamode] #224562
08/30/08 21:08
08/30/08 21:08
Joined: Aug 2008
Posts: 408
mi usa
sadsack Offline
Senior Member
sadsack  Offline
Senior Member

Joined: Aug 2008
Posts: 408
mi usa
pegamode this may help you


handle (object);
Returns a handle of an engine object. A handle is a unique object number that can be assigned to any variable, and identifies that object.
Parameters:
object - ENTITY*, STRING*, BMAP*, VIEW*, PANEL*, TEXT*, FONT*, SOUND*, or MATERIAL* pointer.
Returns:
Handle of object.
Speed:
Fast
Remarks:
A handle is similar to a pointer, but is just a number and therefore can be assigned to any variable or skill.
For getting a handle to a lite-C struct that is not an engine object, use the pVars pointer.
After saving and loading a game, a handle generated by this instruction is guaranteed to reference always the same object - this is not guaranteed for pointers that are just references to memory areas.
On a single player system, the entity handle is valid immediately after entity creation ( (► ent_create). On multiplayer systems, it can take up to 0.5 seconds until the entity is created on all connected machines and the handle becomes valid. During that time the entity handle can not be used.
For using a handle to get the referenced object, it can be converted to a pointer through the ptr_for_handle instruction.
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. The handle can be used to identify the type of the object. 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.
INVALID -1
ENTITY 4 (global)
ENTITY 5 (local)
ENTITY 8 (layer)
STRING 10
FONT 11
BMAP 12
MATERIAL 13
SOUND 14
STREAM 15
TEXT 20
PANEL 21
VIEW 22

Example:
if(entity)
{
my.skill48 = handle(entity); // store entity pointer
}
you = ptr_for_handle(my.skill48); // restore YOU;
See also:
ptr_for_handle, pVars

► latest version online


I have A7 Commercial .............. Now I just need to learn how to use it

Re: How can I set the entity name in script? [Re: pegamode] #224575
08/30/08 22:35
08/30/08 22:35
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Originally Posted By: pegamode
If an entity is set in WED and you call (entity->link).name the name is returned.
Correct.
Originally Posted By: pegamode
If an entity is created by ent_create and you call the same NULL is returned.
Correct, but un-important.
Originally Posted By: pegamode
So an entity created by ent_create has no name ...
Incorrect, true it has no name in link, but using link as a name is a BAAD habit.
The link info really only tells you about how it was created in WED or 'originally' as a global object.

The name you 'should' be using, youve already supplied in your examples. -> player1
Because you will use something like the following to create your entity,
player1 = ent_create (str_create("giana.mdl"), vector(489 , -71 , -150), NULL);
you can from here on refer to this entity as "player1", if you want to rename it
on-the-fly eek then you can always do something like this...
Code:
   ENTITY* player1;         //outside all functions - global pointer is available to all
   ENTITY* giana_mdl_02;    //outside all functions - global pointer is available to all
   ...

   ...
   // inside some function 
   //
   if( player1 != NULL )    // make sure player has been created
   {
      giana_mdl_02 = player1;   // 'aim' new name at our entity        (this line perfectly fine)
      player1 = NULL;           // 'remove' old name from our entity   (try to avoid this line, can get messy)
   }
   ...

from now on you access the same entity, by the new name of "giana_mdl_02". Is this what you're after?

So what do you need the link name for? How do you plan on using it?
If we knew that we would be better able to suggest a better way of doing what you want,
rather than messing around with un-trustworthy INTERNAL data structures.



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: How can I set the entity name in script? [Re: EvilSOB] #224590
08/31/08 07:16
08/31/08 07:16
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hi everybody,

thanks for your answers, but I think I have to explain why I wanted to get / set the entity's name.

I use it as a kind of primary key to store the pointers to my structs that are attached to some of my entities in a hashmap.

For sure it's just one of many things I can use as a primary key, for example the entity's ID, but I liked it because (for debugging reasons) it's more readable than an ID. For that reason I'm currently using entity.type + "_" + ID. That's unique and readable.

One more reason was that I use MadJacks Pathfinding DLL that crashed every time I attached it to an entity created by ent_create ... after debugging the code it turned out that he uses also the entity's name.

Currently I don't have any more issues on that, but as there is not really much information on the entity's name in the manual (or I didn't find it) and I asked myself how I could set that name or why it should be reserved for WED's used only ?!?

Best regards,
Pegamode

Page 1 of 2 1 2

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

Gamestudio download | chip programmers | 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