Page 1 of 2

Side scrolling text function

PostPosted: Mon Jan 15, 2007 5:45 pm
by Novice
Hi everybody, I just made a function to side scroll text action movie style (take a look at the bottom of the post for a preview).
Put this code in global editor
Code: Select all
int time, blink, i;
char temp[255];
 
void type(char myText[255],int speed)
{
     if ( strcmp(&myText[i],"|")!=0  )
     {
        if (time==speed)
        {
           if (i<254&&i!=0)
           {
              strcpy(text,temp);
              strncat(text,&myText[i],1);
              strcpy(temp,text);
              strcat(text,"_");
            }
 
           else
           {
              strncpy(text,&myText[i],1);
              strcpy(temp,text);
           }
 
           time=0;
           i++;
        }
        time++;
      }
      else
      {
          if (time==speed*2)
          {
             if (blink==0)
             {
                strcpy(text,temp);
                strcpy(temp,text);
                blink=1;
             }
             else if (blink==1)
             {
                strcat(text,"_");
                blink=2;
             }
             else
             {
                strcpy(text, temp);
                blink=1;
             }
             time=0;
           }
           time++;
       }
}

In the draw event of your text actor put
Code: Select all
type("20:00\nThe North Valley\nOperation commencing|",3);

Of course change the text to suit your needs, 3 changes the scrolling speed (1 being the fastest).

You have to end a sentence with | or it will get buggy!
| represents the blinking cursor, and tells the function when to stop copying text.
To change to a new row use \n as usual.
You can add sound easily.

The code works fine but I think that it has a few bugs(ex. try leaving | out), so if anyone corrects them or optimizes the code please post it here.
I hope you find a good use for it.
Please post your opinion!

PostPosted: Tue Jan 16, 2007 12:14 am
by Game A Gogo
AHHHHHH
YOUR MY HERO!
Mind if i borrow?

PostPosted: Tue Jan 16, 2007 12:25 am
by Game A Gogo
Just tried it out, works great, but you should also put that you need to insert a font and the first letter of the message (For short...)
But it works like a charm!

PostPosted: Tue Jan 16, 2007 1:40 pm
by Novice
Game A Gogo wrote:Mind if i borrow?

Feel free :wink:
Game A Gogo wrote:but you should also put that you need to insert a font and the first letter of the message (For short...)

What do you mean by this?
Of course you have to select a font, this code is for text actors.
I put a "." so it starts displaying text, otherwise if you leave the text field empty I just shows the pacman icon regardless of the code you use (GE bug?).
This part of code is for overwriting the first letter so you can put anything (like . , _ ).
Code: Select all
           else
           {
              strncpy(text,&myText[i],1);
              strcpy(temp,text);
           }

PostPosted: Wed Jan 17, 2007 12:13 am
by Game A Gogo
well, i jsut start it whit the first character, its not a GE bug, since you cant change a normal actor to a text actor, and since there is no text triggered to the actor, so it stays the same.

PostPosted: Sat Feb 03, 2007 4:18 pm
by Sgt. Sparky
1 + point for you!
Game A Gogo wrote:Mind if i borrow?

could I do the same? :D
did you take classes on how to script? :D

EDIT: I modified it! :D
http://game-editor.com/forum/viewtopic. ... 8696#18696

PostPosted: Sat Feb 03, 2007 9:55 pm
by Novice
Borrow away. :wink:
That's why I put it here.

I didn't have any classes, but I bought a book about C and tried really hard, I'm far from finished.

PostPosted: Sun Feb 04, 2007 3:26 am
by Sgt. Sparky
:shock: what is the book called!?
*drools*

PostPosted: Sun Feb 04, 2007 7:04 pm
by Novice
"The C programming language"

PostPosted: Sun Feb 04, 2007 7:55 pm
by Sgt. Sparky
wow, I should have figured thgat out :D :lol: :oops:

PostPosted: Sun Feb 04, 2007 8:14 pm
by morcior
Theres a million places you can learn C online for free too sparky!

Try typing "C tutorial" into google :)

Also about equally as important for GE, I'd advise reading up on 2D vector maths.. you really only need to understand the most basic concepts like addition, subtraction, lengths, distances and trigonometry and you should find getting your games to behave as you like gets a lot easier!

PostPosted: Sun Feb 25, 2007 3:21 pm
by Troodon
Novice, can I use your code too?
How can I empty and change the text? I have a text:
"Welcome" and I would like it to change when I make something.
I tried to change it with a variable
Code: Select all
if (computerDATA == 0)
{
type("Welcome|",3);
}
if (computerDATA == 1)
{
type("You've entered in the head quarters|",3);
}


but it doesn't help. Please help me.

PostPosted: Sun Feb 25, 2007 3:35 pm
by UltimatHedgehog
do you have something to make computerDATA ==1 you need something for example get a small thing to move left or right and set collision with it to make computerDATA = +1

PostPosted: Sun Feb 25, 2007 3:37 pm
by Troodon
Of course I have something to make computerDATA 1. I have also one to make it 2,3,4 etc.
:)

PostPosted: Sun Feb 25, 2007 3:40 pm
by UltimatHedgehog
explain what it does does it stay at welcome or skip or something