Access string content through another string

Posted By: ChrstphFr

Access string content through another string - 08/15/18 00:45

Dear fellow developers, I have a question that I can't solve on my own.

Is there a way to access the content of a string through its string name, that is itself the string content of another string?

For example:
STRING* content_str = “This is a test!”;
STRING* name_str = “content_str”;

Is it possible to access or copy “This is a test!” through name_str? I want to use entity.string1 to point to another string.

Maybe someone can point my in the right direction.
Posted By: Evo

Re: Access string content through another string - 08/15/18 02:25

Hi ChrstphFr,

If you're talking about just copying one string into another, you can do that by using :
Code:
str_cpy(name_str, content_str);


This will overwrite "name_str" with whatever string you choose and can be changed at anytime within your code.
Posted By: Superku

Re: Access string content through another string - 08/15/18 03:54

Check out engine_getvar: http://www.conitec.net/beta/engine_getvar.htm
Posted By: ChrstphFr

Re: Access string content through another string - 08/15/18 09:30

Thank you Superku! I got it to work with engine_getvar.

Code:
STRING* LookAt_msg = "                                                                ";
STRING* msg_1 = "This is a test.";

...

STRING** temp_msg = (STRING**)engine_getvar(_chr(my.string1),NULL); // entity.string1 is "msg_1"
str_cpy(LookAt_msg,*temp_msg); // LookAt_msg now is "This is a test."

© 2024 lite-C Forums