Page 1 of 1

changing text color by script

PostPosted: Tue May 17, 2016 7:01 pm
by Xpoint
Hi I made a text actor, and the thing I want is when the user clicks on the actor, I need the text's color/font to change

Is there a way to make it done by script maybe ? :(

Re: changing text color by script

PostPosted: Wed May 18, 2016 9:37 am
by lcl
Hi Xpoint! Welcome to the Game Editor forum! I hope you like it here. :)

The only way to change a text actor's color through script is to adjust the actor's r (= red), g (= green) and b (=blue) variables. Each of those variables can have values between 0 and 255, and every actor in Game Editor has it's own r, g and b values. By changing those values you can change the coloring of any actor, including text actors. But note that if you want to be able to use r, g and b to color your text actor with any color you want, the text actor's initial font should be white, as that's when changing r, g and b can have maximum effect on the color of the text. Same goes for other actors - recoloring works best if the actor's animation is white or drawn in grayscale.

But there is also a different way to change a text actor's color in-game. You can use the Set Text -action in any event, like the mosue button down event, as you suggested. Set Text allows you to change the text actor's text, font and color.

I hope this helps! :) And if there's something you don't understand or something else you'd like to ask, please do, I'm willing to help you.

Re: changing text color by script

PostPosted: Wed May 18, 2016 2:45 pm
by Xpoint
lcl wrote:Hi Xpoint! Welcome to the Game Editor forum! I hope you like it here. :)

The only way to change a text actor's color through script is to adjust the actor's r (= red), g (= green) and b (=blue) variables. Each of those variables can have values between 0 and 255, and every actor in Game Editor has it's own r, g and b values. By changing those values you can change the coloring of any actor, including text actors. But note that if you want to be able to use r, g and b to color your text actor with any color you want, the text actor's initial font should be white, as that's when changing r, g and b can have maximum effect on the color of the text. Same goes for other actors - recoloring works best if the actor's animation is white or drawn in grayscale.

But there is also a different way to change a text actor's color in-game. You can use the Set Text -action in any event, like the mosue button down event, as you suggested. Set Text allows you to change the text actor's text, font and color.

I hope this helps! :) And if there's something you don't understand or something else you'd like to ask, please do, I'm willing to help you.

I didn't find the Set Text action, can you precisely tell me how use it ?
because I looked through the functions and the events and couldn't find it.
thanks!!

Re: changing text color by script

PostPosted: Wed May 18, 2016 3:04 pm
by lcl
To find the Set Text -option, choose an event (like mouse button down) and then from the list select Set Text (so, don't select Script Editor). This is how you should be able to find it. :)

Re: changing text color by script

PostPosted: Wed May 18, 2016 3:10 pm
by Xpoint
thanks that worked quit well :D

one more question for now:
when I do this:
onclick:::
textActor->textNumber=0;
strcpy(textActor->text,"-");

the 0 from the text number is still shown , I need the "-" string to be shown instead
is there a way to do it ?? :?:

but when I reclick:::

it show the "-" string

and I want it to be shown from the first time

Re: changing text color by script

PostPosted: Thu May 19, 2016 6:16 am
by lcl
Why exactly do you have to have the "textActor->textNumber = 0;" line there? What do you need it for? The problem you are facing is caused by you trying to use textNumber and text at the same time, you're supposed to only use one of those at a time for a single actor. (Though I'd generally advise against using textNumber at all.)

Re: changing text color by script

PostPosted: Sat May 28, 2016 5:15 pm
by Xpoint
lcl wrote:Why exactly do you have to have the "textActor->textNumber = 0;" line there? What do you need it for? The problem you are facing is caused by you trying to use textNumber and text at the same time, you're supposed to only use one of those at a time for a single actor. (Though I'd generally advise against using textNumber at all.)


I am using it for Sudoku game, I want when the user clicks on the new game button I want to reset the textNumber of my text actors and to zero and I want not to show the 0 symbol instead I want to show the dash "-" symbol

Re: changing text color by script

PostPosted: Thu Jun 02, 2016 11:01 am
by lcl
Sorry for taking so long to answer, I'm on a vacation abroad, and accessing internet is not so easy here.

Xpoint wrote:
lcl wrote:Why exactly do you have to have the "textActor->textNumber = 0;" line there? What do you need it for? The problem you are facing is caused by you trying to use textNumber and text at the same time, you're supposed to only use one of those at a time for a single actor. (Though I'd generally advise against using textNumber at all.)

I am using it for Sudoku game, I want when the user clicks on the new game button I want to reset the textNumber of my text actors and to zero and I want not to show the 0 symbol instead I want to show the dash "-" symbol

Oh, I see. But as I said, I'd still advise against using textNumber, especially because I guess you're going to have to perform some kind of checks on those numbers to see if the Sudoku grid is filled correctly. The textNumber variable should not be used as a way of storing values, it's meant only to be used as a way of displaying numbers (and is actually not that good even for that).

Here's what I'd suggest you to do:
  • Create a new variable called num (for number, you can of course use some other name too), and make it an Integer Actor variable. Now every actor in the game has a new actor variable called num that can store integer numbers.
  • Now you can make your text actors show their number by using a code like this (all text after the first line is comments about the code, not actual code):
    Code: Select all
    sprintf(textActor->text, "%i", textActor->num);

    //ABOUT THE CODE:
    //sprintf is almost the same as strcpy, it just allows you to format the text.
    //The part in quotes is the string that will be printed to textActor->text
    //and the %i means that in that place in the string there will be an integer number.
    //The last argument is the value of the integer to be placed where the %i is, so,
    //in this case the value will be the value of textActor->num.

    //EXAMPLE: in this example the textActor->num is 3
    //The value of textActor->num is placed to where the %i is, so the string becomes "3".
    //The resulting string will be printed to textActor->text, so now it will also be "3".
    //And here's what the text actor will now show on screen: 3
  • And if you want to change the text actor's num value, just do this:
    Code: Select all
    textActor->num = 5; //Replace 5 with the value you want to assign to the actor
  • And for showing the "-" symbol, just use this code:
    Code: Select all
    strcpy(textActor->text, "-");

I hope this helps. However, if you still have questions, just ask and I'll do my best to help you. :)

Re: changing text color by script

PostPosted: Thu Jun 23, 2016 6:05 am
by Xpoint
lcl wrote:Sorry for taking so long to answer, I'm on a vacation abroad, and accessing internet is not so easy here.

Xpoint wrote:
lcl wrote:Why exactly do you have to have the "textActor->textNumber = 0;" line there? What do you need it for? The problem you are facing is caused by you trying to use textNumber and text at the same time, you're supposed to only use one of those at a time for a single actor. (Though I'd generally advise against using textNumber at all.)

I am using it for Sudoku game, I want when the user clicks on the new game button I want to reset the textNumber of my text actors and to zero and I want not to show the 0 symbol instead I want to show the dash "-" symbol

Oh, I see. But as I said, I'd still advise against using textNumber, especially because I guess you're going to have to perform some kind of checks on those numbers to see if the Sudoku grid is filled correctly. The textNumber variable should not be used as a way of storing values, it's meant only to be used as a way of displaying numbers (and is actually not that good even for that).

Here's what I'd suggest you to do:
  • Create a new variable called num (for number, you can of course use some other name too), and make it an Integer Actor variable. Now every actor in the game has a new actor variable called num that can store integer numbers.
  • Now you can make your text actors show their number by using a code like this (all text after the first line is comments about the code, not actual code):
    Code: Select all
    sprintf(textActor->text, "%i", textActor->num);

    //ABOUT THE CODE:
    //sprintf is almost the same as strcpy, it just allows you to format the text.
    //The part in quotes is the string that will be printed to textActor->text
    //and the %i means that in that place in the string there will be an integer number.
    //The last argument is the value of the integer to be placed where the %i is, so,
    //in this case the value will be the value of textActor->num.

    //EXAMPLE: in this example the textActor->num is 3
    //The value of textActor->num is placed to where the %i is, so the string becomes "3".
    //The resulting string will be printed to textActor->text, so now it will also be "3".
    //And here's what the text actor will now show on screen: 3
  • And if you want to change the text actor's num value, just do this:
    Code: Select all
    textActor->num = 5; //Replace 5 with the value you want to assign to the actor
  • And for showing the "-" symbol, just use this code:
    Code: Select all
    strcpy(textActor->text, "-");

I hope this helps. However, if you still have questions, just ask and I'll do my best to help you. :)


thanks a lot that worked well.

Sorry I forget to thank you before but the pressure of work and collage made me forget.

Re: changing text color by script

PostPosted: Fri Jun 24, 2016 12:38 pm
by lcl
Xpoint wrote:thanks a lot that worked well.

Sorry I forget to thank you before but the pressure of work and collage made me forget.

Don't worry. :) I'm glad I was able to help you.