Changing Strings at runtime

Posted By: Toryno

Changing Strings at runtime - 09/21/09 15:26

How can I change the string of digits or of a TEXT* ? (at runtime)
Posted By: DJBMASTER

Re: Changing Strings at runtime - 09/21/09 15:30

You can use the pstring array together with str_cpy...

str_cpy((my_text.pstring)[7], "Hello"); // Set 8th string to "Hello"

The 7 in the [] is the index of the string to edit, in this case it would edit the 8th string (indexes start with 0).
Posted By: Saturnus

Re: Changing Strings at runtime - 09/21/09 15:33

And you can use pan_setdigits() to modify digits.
Posted By: Widi

Re: Changing Strings at runtime - 09/21/09 15:57

if you have only one String (no Array) you can use str_cpy
Posted By: Toryno

Re: Changing Strings at runtime - 09/21/09 17:00

Hmm, can you say me what this code makes?


STRING* my_string = "hello";
...
my_string = "bye"; // I mean this line
Posted By: Quad

Re: Changing Strings at runtime - 09/21/09 17:01

str_cpy(my_string,"bye");
Posted By: Toryno

Re: Changing Strings at runtime - 09/21/09 17:20

Aha, so that's the same =D

But it still don't want to work correctly, when the function chose_target is called, you can't see the digits no more. Why?

Code:
PANEL* targets =
{
	layer = 5;
	button = 0,0, cg_released_pcx, cg_normal_pcx, cg_over_pcx,chose_target,NULL,NULL;
	digits = 2,2, "target: first", "Arial#24", 0, 0;
}

void chose_target() {
	pan_setdigits(targets,1,2,2, "target: last", "Arial#24", 0, 0);
}


Posted By: ptrc1c

Re: Changing Strings at runtime - 09/21/09 23:23

Hi Toryno,
I have found a way to do this

////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

////////////////////////////////////////////////////////////////////

STRING* temp_text ="pete";

var* tee;
tee = 3;
function main()
{
video_mode = 7;
screen_color.blue = 150;
mouse_mode = 4;
}



//////////////////////////////////////////////////////////////////////

PANEL* main_pan =
{
bmap = "main.pcx";
pos_x = 250;
pos_y = 200;
button (250, 134, "quitclicked.pcx", "quitnormal.pcx", "quitover.pcx", quit_program, NULL, NULL);
digits (200,100, "%s",*,1,temp_text);
flags = OVERLAY | VISIBLE;
}

function quit_program()
{

str_cpy(temp_text,"Its changed");

}
Posted By: Toryno

Re: Changing Strings at runtime - 09/22/09 06:19

Yes, thats good! Thank you laugh
© 2024 lite-C Forums