Page 1 of 1

sprintf

PostPosted: Thu Feb 23, 2006 7:31 pm
by plinydogg
I'm trying to make an onscreen keyboard (to use instead of the SIP) and I think I need to use sprintf but can't figure out how to get it to work.

When the text actor that displays the name is created, I have the following pseudocode in create actor -> script editor:

stringvar = "";

Then, when you press the stylus down on a letter, say "q" for example, the following code is executed:

sprintf(stringvar, TextActor.text); //set stringvar = already typed letters
sprintf(TextActor.text, "q", stringvar); // concatenate stringvar and "q" and display the result in TextActor.text

When I add similar code to other letters, I can get TextActor to display the letter most recently typed, but cannot get it to add any letters (i.e., TextActor only displays one character...the most recently typed one).

I'm sure this is just me not knowing how to use sprintf.

Help is much appreciated!

PostPosted: Thu Feb 23, 2006 11:20 pm
by makslane
Use strcpy to copy and strcat to concatenate strings:

strcpy(stringvar, TextActor.text);
strcat(TextActor.text, "q");
strcat(TextActor.text, stringvar);

Look sprintf sample here:
http://www.google.com/search?sourceid=n ... f+examples

PostPosted: Fri Feb 24, 2006 8:36 pm
by plinydogg
Thanks for the help makslane but I'm still having difficulty. I think I'll try to take a different approach. How about this:

char TextArray[9];
int placeHolder = 0;

//on a mousedown event for the letter "q":

TextArray[placeHolder] = "q";
placeHolder++;

//Do the same for the other letters.

Question: how can I convert the char array (TextArray) into a string so that I can place it in TextNumber?

Thanks in advance!

PostPosted: Sat Feb 25, 2006 12:46 am
by makslane
If you need save a key sequence, look the thread:
http://game-editor.com/forum/viewtopic. ... ight=cheat

PostPosted: Sat Feb 25, 2006 2:58 pm
by plinydogg
Just what needed! Thanks makslane!