How to set to lines of text? (multiple problems)

Non-platform specific questions.

How to set to lines of text? (multiple problems)

Postby Garfield501 » Mon Oct 12, 2009 6:29 pm

I have two problems.

PROBLEM 1:
I want to change the text of my actor named: "Textbar_text"

in the script editor i am using this code:
Code: Select all
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text,"Welcome to this game. I'll explain the rules for you now.");
}

(The variable "Textbar_text_counter_value" checks what text should be displayed.)

What I want is that this text is displayed over two lines.
So you get the following:

"Welcome to this game."
"I'll explain the rules for you now."

But with my current code, it just shows it in one long line.
This way, from "explain" and further, it is showed outside of the screen.

How can I set the text over two lines?




PROBLEM 2:
Problem 1 has not been solved yet!


Code: Select all
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text,"Welcome to this game. I'll explain the rules for you now.");
    char *key_state = GetKeyState(); //Get entire keyboard state
    if(key_state[KEY_RETURN] == 1) //Test if right key is pressed
    {
        Textbar_text_counter_value = 2;
    }
}

I have added some code. After it displayed the text, it is supposed to check what key is pressed.
In my game it is the ENTER or the Return key.

now it comes with the following errors.

Error line 8: Unexpected declaration strcpy
Warning line 8: Trying convert from '* char' to '* char * char'


What did I do wrong here?
I just followed the documentation.
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby skydereign » Mon Oct 12, 2009 9:10 pm

This should work. The first thing I changed is to declare the char* earlier. You should declare variables at the beginning of the script event. You can also declare them right after certain conditionals, like the if statement, but for the most part I don't suggest it. The reason being, with most variables it is okay to make them global for the script, and it can cause confusion if you make each exclusive to certain ifs. The second change was to make newlines in text, you have to insert a newline, which is this \n.

Code: Select all
char *key_state = GetKeyState(); //Get entire keyboard state
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text, "Welcome to this game.\nI'll explain the rules for you now.");
    if(key_state[KEY_RETURN] == 1) //Test if right key is pressed
    {
        Textbar_text_counter_value = 2;
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby Garfield501 » Tue Oct 13, 2009 1:55 pm

okay, well this part works, but when I expanded the code, i got the next problem.

PROBLEM 3:
Code: Select all
char *key_state = GetKeyState(); //Get entire keyboard state

if (Textbar_text_counter_value == 2)
{
    strcpy (Textbar_text.text,"To move left, press the left-key direction key.\nTo move to the right, press the right-direction key.");
    if(key_state[KEY_RETURN] == 1 && Textbar_text_counter_value == 2) //Test if return key is pressed
    {
        Textbar_text_counter_value = 3;
        key_state[KEY_RETURN] = 0;
    }
}
if (Textbar_text_counter_value == 1)
{
    strcpy (Textbar_text.text,"Welcome to this game.\nI'll explain the rules for you now.");
    if(key_state[KEY_RETURN] == 1 && Textbar_text_counter_value == 1) //Test if return key is pressed
    {
        Textbar_text_counter_value = 2;
        key_state[KEY_RETURN] = 0;
    }
}
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text,"");
    key_state[KEY_RETURN] = 0;
}


Now the new problem is that it skips everything and it shows the "To move left, press the left-key direction key.\nTo move to the right, press the right-direction key."-part.
How can I make it, that it start showing "Welcome to this game.\nI'll explain the rules for you now." and when I press the RETURN-key, it shows the next text-part --> "To move left, press the left-key direction key.\nTo move to the right, press the right-direction key.".
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby MrJolteon » Tue Oct 13, 2009 2:10 pm

Garfield501 wrote:I have two problems.

PROBLEM 1:
I want to change the text of my actor named: "Textbar_text"

in the script editor i am using this code:
Code: Select all
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text,"Welcome to this game. I'll explain the rules for you now.");
}

(The variable "Textbar_text_counter_value" checks what text should be displayed.)

What I want is that this text is displayed over two lines.
So you get the following:

"Welcome to this game."
"I'll explain the rules for you now."

But with my current code, it just shows it in one long line.
This way, from "explain" and further, it is showed outside of the screen.

How can I set the text over two lines?

Try with this:
Code: Select all
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text,"Welcome to this game.\nI'll explain the rules for you now.");
}

see that \n between the two sentences? That is a code to make text after it appear on the next line, and itself disappears.
Join us on Discord!
Game Editor 2
These are the best ways to reach me these days


Your local Community Janitor, always lurking in the shadows...
User avatar
MrJolteon
 
Posts: 2326
Joined: Sat Aug 09, 2008 3:25 pm
Location: Stranded under endless sky
Score: 105 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby Garfield501 » Tue Oct 13, 2009 2:53 pm

Yes, thanks you.
This works fine now.


Only this problem is left.
Garfield501 wrote:okay, well this part works, but when I expanded the code, i got the next problem.

PROBLEM 3:
Code: Select all
char *key_state = GetKeyState(); //Get entire keyboard state

if (Textbar_text_counter_value == 2)
{
    strcpy (Textbar_text.text,"To move left, press the left-key direction key.\nTo move to the right, press the right-direction key.");
    if(key_state[KEY_RETURN] == 1 && Textbar_text_counter_value == 2) //Test if return key is pressed
    {
        Textbar_text_counter_value = 3;
        key_state[KEY_RETURN] = 0;
    }
}
if (Textbar_text_counter_value == 1)
{
    strcpy (Textbar_text.text,"Welcome to this game.\nI'll explain the rules for you now.");
    if(key_state[KEY_RETURN] == 1 && Textbar_text_counter_value == 1) //Test if return key is pressed
    {
        Textbar_text_counter_value = 2;
        key_state[KEY_RETURN] = 0;
    }
}
if (Textbar_text_counter_value == 0)
{
    strcpy (Textbar_text.text,"");
    key_state[KEY_RETURN] = 0;
}


Now the new problem is that it skips everything and it shows the "To move left, press the left-key direction key.\nTo move to the right, press the right-direction key."-part.
How can I make it, that it start showing "Welcome to this game.\nI'll explain the rules for you now." and when I press the RETURN-key, it shows the next text-part --> "To move left, press the left-key direction key.\nTo move to the right, press the right-direction key.".
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby Garfield501 » Thu Oct 15, 2009 4:55 pm

Anyone who can help me with this issue??

I have tried a lot of things, but it still doesn't do what I want.
I searched for tutorials, but couldn't find, what I am looking for.

I am getting a bit desperate. It's a big problem, because I am having this problem for a few days and I can't solve it.
Garfield501
 
Posts: 25
Joined: Tue Sep 22, 2009 5:45 pm
Score: 0 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby jimmynewguy » Fri Oct 16, 2009 1:02 am

try turning key repeat off, it might just be repeating and making the variable go up faster then u can tell (this happend to me once)

EDIT: It's on draw actor, so it's repeating, not the key down event. I think your just gonna have to make key down events instead of getting the key state :)
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: How to set to lines of text? (multiple problems)

Postby DST » Fri Oct 16, 2009 4:01 am

Textbar_text_counter_value? Ur kidding right?

Ahem, i mean "You_are_kidding_right"?

how bout textor. Just textor.

strcpy(textor.text, "I_hate_typing_unnecessarily_long_variable_and_actor_names_with_shift_keys")


I name them after other game characters that i like. Like Lavos from ChronoTrigger.

Thus, i name my canvas actor 'canvos'. It brings back great memories and is simple to type.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron