|
Re: How can I set the entity name in script?
[Re: pegamode]
#224597
08/31/08 07:57
08/31/08 07:57
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Aha, I see. Ive never played with hashmaps and havent really tried to understand the concepts yet, thats a job for later... BUT, here is an exceptionally ugly and mem-leaky little piece of code that I use in a tool Im building that creates light entities and 'gives' them unique names. LightEnt = ent_create(Globe_MDL, nullpointer, NULL);
STRING* tmp = str_create("GlobeLight_01");
LightEnt.link.name = tmp.chars; Its dirty but it works. The concept may give you ideas and if you come up with something similar it may solve MadJacks crashes. I'll be redoing my above snippet in an estimated few days to be 'clean' by using malloc instead of a sacrificial string. If you want it, I'll post it in here when its done.
"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]
#224609
08/31/08 09:51
08/31/08 09:51
|
Joined: Jun 2005
Posts: 87 France
MadJack
Junior Member
|
Junior Member
Joined: Jun 2005
Posts: 87
France
|
Just a precision, in my DLL I assumed that each entity had a name. My mistake Since Pegamode has pointed that it was not true using ent_create, we have corrected the DLL code. But for general purpose, it might be interesting to set the entity name by script... Pegamode, did you test EvilSOB's solution ?
|
|
|
Re: How can I set the entity name in script?
[Re: pegamode]
#224816
09/01/08 11:27
09/01/08 11:27
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Yeah, I tried it this way to start too, but LightEnt.link.name = tmp; wont work cause the link.name REQUIRES its data to be JUST a CHAR array, not a whole STRING structure. Big difference.
By using LightEnt.link.name = tmp.chars;, I am only using the CHAR array element of the string structure.
"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]
#224941
09/02/08 04:50
09/02/08 04:50
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
OK guys, heres the Renamer snippet I promised. Tweaked it a bit so now it will work on almost any object type, BMAP,TEXT, ENTITY, etc.
...
// example usages
Rename_Link(Model.link, "New_Name1");
...
STRING* tmpName = str_create("Test_Name_two");
Rename_Link(Model2.link, tmpName);
...
function Rename_Link( C_LINK* Link, STRING* NewName )
{ // Either INSERTS or REPLACES the C_LINK.name field with supplied NewName.chars
// If C_LINK* is NULL, function will just exit
// If STRING* is NULL, function will replace C_LINK.name with NULL
//
if(Link==NULL) return; //Cant process UNDEFINED object
if(Link.name!=0) free(Link.name); //Erase existing
Link.name=0; // Link Name
if(NewName==NULL) return; //Leave Link name empty as requested
Link.name = (char*)malloc((long)str_len(NewName)+1); //create Name space
memcpy(Link.name,_chr(NewName),str_len(NewName)+1); // & copy Name into space
} Any questions or problems, let me know. Enjoy.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|