Custom side scrolling text function[UPDATED]!

You must understand the Game Editor concepts, before post here.

Custom side scrolling text function[UPDATED]!

Postby Sgt. Sparky » Fri Apr 20, 2007 6:14 am

Here is a side scrolling text function that can use sound,
Novice made one and he said to post if it was modified,
so I made one from scratch that can reset itself. :D
I fixed a few buggy things and you do not need to finish it with a |
I thought there would be a simpler solution, but it turned out to be a bit more complicated then what I though it would be,
I just made this function really quick so it might not be that good,
but here is what you put in the global
Code: Select all
int wait, started, flash, skip, finish, sel;
int i, I, i2, c;
wait = 0;
i = 0;
started = 0;
flash = 0;
skip = 0;
finish = 0;
void wait_action(float vol)
{
   PlaySound2("data/c1.wav", vol, 1, 0.000000);
}
void type_out(char txt[255], char s[1],int num, int del)
{
 
    if(strlen(s) > 1)strncpy(s, s, 1);
    if(started == 0)
    {
        i = 0;
        finish = 0;
        flash = 0;
        strcpy(text, "0");
        strcpy(text, s);
        started = 1;
    }
    I = strlen(txt);
    i2 = strlen(text) - 1;
    wait -= 1;
    if(wait <= 0 && i < I)
    {
        wait_action(.5);
        strcpy(&text[i2], " ");
        strncat(text, &txt[i], 1);
        strcat(text, s);
        i++;
        wait = num + round(rand(del));
    }
    if(wait <= 0 && i >= I)
    {
        finish = 1;
        if(flash == 0) {
        skip = 1;
        flash = 1;
                       }
        if(skip == 0) {
        if(flash == 1)flash = 2;
        else
        {
            flash = 1;
        }
                      }
        skip = 0;
        if(flash == 1) {
        strcpy(&text[i2], "");
                       }
        if(flash == 2) {
        strncat(&text[i], s, 1);
                       }
        wait = num * 3;
    }
}
void reset_type(int m)
{
    finish = 1;
    started = 0;
    c++;
    if(c > m)c = 0;
    sel = c;
}

this version is the old one that has a few more vars, but the .exe seems to crash :(
Code: Select all
char s1[255], s2[255];
int wait, started, flash, skip, finish, sel;
int i, I, i2, c;
wait = 0;
i = 0;
started = 0;
flash = 0;
skip = 0;
finish = 0;
void type_out(char txt[255], char s[1],int num, char l[255], char l2[255], int del, float vol)
{
 
    if(strlen(s) > 1)strncpy(s, s, 1);
    if(started == 0)
    {
        sprintf(s1, "data/%s", l);
        sprintf(s2, "data/%s", l2);
        i = 0;
        finish = 0;
        flash = 0;
        strcpy(text, "0");
        strcpy(text, s);
        started = 1;
    }
    I = strlen(txt);
    i2 = strlen(text) - 1;
    wait -= 1;
    if(wait <= 0 && i < I)
    {
        PlaySound2(s1, vol, 1, 0.000000);
        strcpy(&text[i2], "");
        strncat(text, &txt[i], 1);
        strcat(text, s);
        i++;
        wait = num + round(rand(del));
    }
    if(wait <= 0 && i >= I)
    {
        finish = 1;
        if(flash == 0) {
        skip = 1;
        flash = 1;
                       }
        if(skip == 0) {
        if(flash == 1)flash = 2;
        else
        {
            flash = 1;
        }
                      }
        skip = 0;
        if(flash == 1) {
        strcpy(&text[i2], "");
                       }
        if(flash == 2) {
        PlaySound2(s2, vol, 1, 0.000000);
        strncat(&text[i], s, 1);
                       }
        wait = num * 3;
    }
}
void reset_type(int m)
{
    finish = 1;
    started = 0;
    c++;
    if(c > m)c = 0;
    sel = c;
}

old one: here it is taken apart: type_out("your text", "the character you want it to append", the delay number, "the name of the sound.its type that you want to play while it types it out", "the name of the second sound you want it to play when it finishes.", the random delay number, the volume number);//volume number range is from 0 to 1 :)
new one: type_out("your text", the character you want to append it with", the delay number, the added onto random delay number);
:D
the new one is alot simpler! :)
to make it play a sound for the wait_action just modify the global code there to match the sound you want it to play :)
all you have to do is save the sounds you want in you're games data folder,
then if you wanted it to play beep1 for each character, and beep2 when it finishes and the appended char is flashing and if the sounds are .wav, and the character to append it with is |, and if you wanted it to type out hello kind of fast use this,
Code: Select all
type_out("hello", "|", 3, "beep1.wav", "beep2.wav", 6, .5);

:D
you do not have to make sel a variable, it will make it for you.
on the event you want to change the value of sel,
use reset_type(3);
the number inside the () represents the max value of sel,
you can change this to whatever you want and add more if(sel == events :D
enjoy!
if there are any questions let me know. :)
Feel free to use it! :D
(I would like a mention in the credits :), but you do not have to if ya' do not want to.)
oh, and you can still use \n and all those other text functions. :)
UPDATED WITH VOLUME SELECT FOR SOUND!
http://www.youtube.com/watch?v=oN2eUKe0Bek
here is a video link to view somthing that you could make, the video is unedited. :)
Last edited by Sgt. Sparky on Sun Apr 22, 2007 2:03 pm, edited 13 times in total.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby morcior » Fri Apr 20, 2007 11:27 am

I have to say, novices code is cleaner, makes a lot more sense and doesn't use 200 variables (so uses less memory). You also forgot to append a "_". Its a nice try sparky, but if you were looking to improve novices code, his existing code might have been a good starting point :oops:
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Sgt. Sparky » Fri Apr 20, 2007 9:06 pm

erm, look at the code, you can append it with whatever character you want.
I am adding it soon so you can use a whole word at the end...

and why do you discredit it without even tryin' it?...
I would not mind if you had tried it and and then discredited it.

but what you are sayin' is not valid with my code.....
therefore you could not have tried it...:|
Last edited by Sgt. Sparky on Sat Apr 21, 2007 12:06 am, edited 1 time in total.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Sgt. Sparky » Fri Apr 20, 2007 11:22 pm

UPDATED! :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Game A Gogo » Sat Apr 21, 2007 2:09 am

morcior wrote:I have to say, novices code is cleaner, makes a lot more sense and doesn't use 200 variables (so uses less memory). You also forgot to append a "_". Its a nice try sparky, but if you were looking to improve novices code, his existing code might have been a good starting point :oops:

Variable consume very less memory, an array of 256 would not use more then 65kb which is not a lot,so even whit all the thing, i would think it would come up as: 327kb and I'm sure you would agree thats not a lot.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby morcior » Sat Apr 21, 2007 2:27 am

I'm just saying,

novices code:
Code: Select all
int time;
int blink;
int i;
char temp[255];

= 267 bytes

vs

sparkys code:
Code: Select all
char smpl[255];
char smpl2[255];
char smpl3[255];
char s1[255];
char s2[255];
int wait
int started
int flash;
int skip;
int finish;
int sel;
int i;
int I;
int i2;
int c;

= 1,315 bytes

when both perform basicly the same function. Its a small amount sure, but these things can build up, especially on a mobile device.

Plus its just bad programming practise to waste memory.
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Game A Gogo » Sat Apr 21, 2007 2:43 am

yes, i understand your point.

Wasting memory is not really good idea, but also there is the result that counts.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Sgt. Sparky » Sat Apr 21, 2007 3:12 am

yeah, I think all the sound gizmo and special customizations are worth it :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Sgt. Sparky » Sat Apr 21, 2007 9:41 pm

I just added a custom volume select :)
See above at the top of the page ^
:):):):):):):):):):):):):):) | |
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

erm..

Postby kyensoftware » Sun Apr 22, 2007 10:16 am

erm.....sparky,....it just says W(square glitchy blocky thing) instead of Welcome!
:? :? :? :? :? :? :cry: :cry: :cry: :cry: :cry: :? :? :? :? :? :? :?
EDIT:Fixed it....i had used a corrupted font...*sobs* prob now is...and this is gonna sound stupid....how do you go to the next line?? you cant use /n???
Erm...WHERE THE HELL DID THAT POST THERE COME FROM????
Last edited by kyensoftware on Sun Apr 22, 2007 2:03 pm, edited 2 times in total.
User avatar
kyensoftware
 
Posts: 198
Joined: Thu Oct 26, 2006 7:49 am
Score: 5 Give a positive score

Postby Sgt. Sparky » Sun Apr 22, 2007 1:18 pm

hmmm,
you put it in global code, you added it,
and on the draw actor event of you're text actor you put,
Code: Select all
type_out("Welcome!, "|", 5, "your sound.what it is", "your second sound.what it is", 3, .5); ?
those numbers can be whatever you want along with the text and sound ofcourse,
but did you put it in the draw actor event?
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

enter?

Postby kyensoftware » Sun Apr 22, 2007 3:32 pm

What I need to know, is how to make a new line, and /n dont work!
EDIT:Of course that wont work! I mixed up teh slashes!!
User avatar
kyensoftware
 
Posts: 198
Joined: Thu Oct 26, 2006 7:49 am
Score: 5 Give a positive score

Postby Sgt. Sparky » Sun Apr 22, 2007 9:39 pm

xD yeah, \n is new line \t is tab \b is backspace but there is some glitch in GE when I tried to use \b as backspace for my repeated typing function(the name of the topic is repeated typing function) :(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

what dos it doo

Postby kyensoftware » Mon Apr 23, 2007 4:14 am

what dos /t (tab) doo?
User avatar
kyensoftware
 
Posts: 198
Joined: Thu Oct 26, 2006 7:49 am
Score: 5 Give a positive score

Postby Sgt. Sparky » Tue Apr 24, 2007 3:36 am

you know there is a tab button on your keyboard,
when it makes a big space that evens out lines,
like if the lines printed uneven text you could begin each line with \t and every line would be even(verticle) :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest