please make it possible to change entity.string1 / 2

Posted By: Reconnoiter

please make it possible to change entity.string1 / 2 - 05/23/15 13:03

Hi JCL and co,

It would be really nice if entity.string1 and entity.string2 could be changed realtime. I am making a realtime map editor and it would be nice to save 2 actions/strings; 1 for in the editor itself (also for the entity action when opening a saved map in the editor) and 1 for the game (script). But the manual points out the it is read-only.

Quote:
entity.string1 ... entity.string2
Two general-purpose 32 character strings. Can be set by WED's entity properties panel and can be read in the script by the str_cpy or str_cat functions, but must not be altered.
Type:
char* pointer, read-only


Is it possible to bypass the read-only thingy?

Thanks in advance.
Posted By: AceX

Re: please make it possible to change entity.string1 / 2 - 05/23/15 14:08

You can use a entity skill as a string too grin
Posted By: Ch40zzC0d3r

Re: please make it possible to change entity.string1 / 2 - 05/23/15 15:33

Forget the read only stuff...
Nothing in memory is really read-only (just when the process constantly writes to the address which is not the case here).
So you either just call str_cpy and if it fails you can use VirtualProtect to change the page protections because it might be protected (ReadOnly).
Posted By: sivan

Re: please make it possible to change entity.string1 / 2 - 05/23/15 18:52

if you need to store data on creating a wmb, I use it in MapBuilder, just save the info in the editor into a skill over 20 (the 1st 20 skills are saved into wmb), then get the string when you write the 2 strings into the new wmb. check my source, it is easy (I use it for storing decal shadow file name needed for free/extra license users).
Posted By: Reconnoiter

Re: please make it possible to change entity.string1 / 2 - 05/24/15 10:01

Thanks for all the quick responses;

Originally Posted By: AceX
You can use a entity skill as a string too grin
, true but that would be sacrificing 1 one of the 20 skills the user otherwise can use for e.g. stats like hit points to save in a .wmb map file.

Originally Posted By: Ch40zzC0d3r
Forget the read only stuff...
Nothing in memory is really read-only (just when the process constantly writes to the address which is not the case here).
So you either just call str_cpy and if it fails you can use VirtualProtect to change the page protections because it might be protected (ReadOnly).
, oh nice, ty for the tip.


Originally Posted By: sivan
if you need to store data on creating a wmb, I use it in MapBuilder, just save the info in the editor into a skill over 20 (the 1st 20 skills are saved into wmb), then get the string when you write the 2 strings into the new wmb. check my source, it is easy (I use it for storing decal shadow file name needed for free/extra license users).
, with source you mean your Map Builder source? I try to download it but both the mirrors don't work. But why actually not directly save the string into entity.string?
Posted By: txesmi

Re: please make it possible to change entity.string1 / 2 - 05/24/15 17:47

Code:
if ( my->string1 )
   my->string1 = str_create ( my->string1 );

Posted By: WretchedSid

Re: please make it possible to change entity.string1 / 2 - 05/24/15 18:14

Of course, all of this is going to break the second the strings are used internally. Or hashed and that hash is used internally.

Has none of you guys mothers told you that you don't just walk into your neighbours house and take their bread? You keep your grabby fingers off of memory that isn't yours.
Posted By: FBL

Re: please make it possible to change entity.string1 / 2 - 05/24/15 20:05

Neighbour's house was left empty and is slowly falling apart. So it is the perfect playground.
Posted By: WretchedSid

Re: please make it possible to change entity.string1 / 2 - 05/24/15 21:50

Rumour has it there is a ghost still living there, not being able to find a final resting place. Also, don't eat moldy bread found in your neighbours rotten house. Chances are that the stuff growing on it is not in fact penicillin.
Posted By: Superku

Re: please make it possible to change entity.string1 / 2 - 05/25/15 03:33

I see two separate questions/ things in this thread/ OP. The first thing is to be able to modify string1/2, but as stated by others you can just create a string and save it in one of the 100 skills.
The second thing is that you want to attach 2 actions to your entities because of editor/ ingame differences. Alternatively, I think it would be a better way to save additional data in a *.txt file from which you then load map editor related actions for each entity if necessary (and suppress the execution of the actual entity action).
Posted By: jcl

Re: please make it possible to change entity.string1 / 2 - 05/25/15 09:42

string1/2 can be modified - nothing evil will happen (I hope). You only must be aware that they are char* pointers, so they do not store a string content, but only its pointer.
Posted By: Reconnoiter

Re: please make it possible to change entity.string1 / 2 - 05/25/15 10:03

Thanks guys for all the replies;

Originally Posted By: WretchedSid
Of course, all of this is going to break the second the strings are used internally. Or hashed and that hash is used internally.
, but the wmb compiler saves the entity.strings, the manual points this out itself, maybe I misinterpreting your comment.


Originally Posted By: Superku
I see two separate questions/ things in this thread/ OP. The first thing is to be able to modify string1/2, but as stated by others you can just create a string and save it in one of the 100 skills.
, only 20 skills are saved for wmb, I already use 2 of them (1 for alpha value cause wmb does not save this >> , and 1 for ID), so I want to leave others alone.
Leave the skills alone grin <bad joke>.

Originally Posted By: Superku
second thing is that you want to attach 2 actions to your entities because of editor/ ingame differences. Alternatively, I think it would be a better way to save additional data in a *.txt file from which you then load map editor related actions for each entity if necessary (and suppress the execution of the actual entity action).
, well this is something I am still pondering about what is the best solution. My idea was to set the editor action through ent_create since the game action does not yet exist at that time, cause its not the game script. So I thought I would let the user being able to type/c&p the wanted entity action string so it can be saved into the entity.string1 . Than the user can add the editor action in his script and from there:
- call the right game script action/function (saved into entity.string1) or based of maybe the enttiy's ID. Or ent_filename for the slow approach.
- return;

But I see some flaws with this. One is adding extra mess to the user's script (though I doubt if this can be solved). But mainly this puts up a limit of max entities based on the max function/action limit. So I am thinking about removing the whole editor action dependence all together and replace it with 1 function that check ents through ent_next and mouse_ent for click/touch events. Than just add a dummy entity action pure for this user to acces the entity in game script and give it a new (/ the right) action.

ps: is there an elegant line that runs a function for an entity based on a string?

-edit, just saw your response JCL, thanks for replying.
Quote:
string1/2 can be modified - nothing evil will happen (I hope). You only must be aware that they are char* pointers, so they do not store a string content, but only its pointer.
, so its useless for saving to wmb?
© 2024 lite-C Forums