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 2 of 2 1 2
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 Offline
Expert
EvilSOB  Offline
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.
Code:
   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 Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
Just a precision, in my DLL I assumed that each entity had a name. My mistake blush
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 ?


Commercial A7.25b
RUGod
Re: How can I set the entity name in script? [Re: MadJack] #224622
08/31/08 12:19
08/31/08 12:19
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 it that way:

STRING* tmp = str_create("GlobeLight_01");
LightEnt.link.name = tmp;

With no compiler error, but still NULL in link.name in the DLL.

I'll test

LightEnt.link.name = tmp.chars;

as soon as possible.

Re: How can I set the entity name in script? [Re: pegamode] #224624
08/31/08 12:28
08/31/08 12:28
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
hmmm ...

very strange, I checked it again and now both variants are running well ?!?

Also LightEnt.link.name = "GlobeLight_01"); runs well.

I don't know why, but as I checked it yesterday I got NULL ... now it's working. Don't know where's the difference.

So, to sum it up:

The entity's name can be set using entityName.link.name and also string1 / string2 can be set with entityName.string1 although they are read-only.

Best regards,
Pegamode.

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 Offline
Expert
EvilSOB  Offline
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 Offline
Expert
EvilSOB  Offline
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.

Code:
   ...
   // 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
Page 2 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