How To Create/WriteonScreen/Check/Compare Strings

Non-platform specific questions.

How To Create/WriteonScreen/Check/Compare Strings

Postby ggesterGamePro99 » Mon Apr 16, 2012 9:24 pm

I tried learning about arrays but i didn't see much in any documentation around.

My basic questions are

1. How do you create a string ?
In Java which i learned before it was String s = "ff"

Is it the same?

2. How to you Write the text on the screen at any part of the screen that you want? And also how do you set the Font and Font size for that text?

3. How do you compare strings to be the same or concatenate strings et?. String operations

4. How do you allow the user to type in text like a password or even
to write text on the screen.

and how do you grab that inputed text and perform checks or operations on it?
ggesterGamePro99
 
Posts: 44
Joined: Mon Apr 16, 2012 1:53 am
Score: 0 Give a positive score

Re: How To Create/WriteonScreen/Check/Compare Strings

Postby skydereign » Mon Apr 16, 2012 11:32 pm

First of all, arrays are pretty well explained on the forum. Though gE itself assumes you know C (so there wouldn't be formal documentation on it).
1. Strings in C are either char*s or char arrays. If you don't know dynamic memory allocation, I suggest using char arrays.
Global Code
Code: Select all
char string[50]; // declares a 50 character long string named string
char other_string[30]; // declares a 30 character long string named other_string


2. To display text on screen, you have to use a text actor. To make a text actor, use a normal actor, and in the actor control panel, click font. From there add a ttf file, and some text in the window. Then use string manipulation functions on that actor's text. For instance...
actor -> Create Actor -> Script Editor
Code: Select all
strcpy(text, "Here is some text");

I suggest you search and/or look into sprintf. But, since these are actors, you can move them around like you would any other actor.

3. To compare strings you have to use strcmp. strcmp(char* s1, char* s2), it will return 0 if the two strings are the same. Also note that char arrays are technically char*s so you can use char* and char arrays interchangeably. To concatenate you use strcat.

4. You can use gE's built in text input, which is accessed when you click font in the actor control panel. You should be able to enable it from there.

Lastly you can use point 4's system which alters the actor's text variable. That way you can grab the text variable to check or otherwise manipulate.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How To Create/WriteonScreen/Check/Compare Strings

Postby ggesterGamePro99 » Tue Apr 17, 2012 12:16 am

Awesome. Thanks Alot.
Yeah, i didn't know where to look for documentation on strings, so thanks alot
ggesterGamePro99
 
Posts: 44
Joined: Mon Apr 16, 2012 1:53 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest