Page 1 of 1

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

PostPosted: Mon Oct 12, 2009 6:29 pm
by Garfield501
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.

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

PostPosted: Mon Oct 12, 2009 9:10 pm
by skydereign
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;
    }
}

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

PostPosted: Tue Oct 13, 2009 1:55 pm
by Garfield501
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.".

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

PostPosted: Tue Oct 13, 2009 2:10 pm
by MrJolteon
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.

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

PostPosted: Tue Oct 13, 2009 2:53 pm
by Garfield501
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.".

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

PostPosted: Thu Oct 15, 2009 4:55 pm
by Garfield501
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.

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

PostPosted: Fri Oct 16, 2009 1:02 am
by jimmynewguy
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 :)

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

PostPosted: Fri Oct 16, 2009 4:01 am
by DST
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.