typing effect

closed account (4Gb4jE8b)
I was able to figure out a simple typing effect on the console without too much trouble, but then i went complex (mostly because i was bored), and now i'm stuck :P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
void wait ( double seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
}

void type_erase(std::string content, int placement, int backspace, double time_delay)
{
	//note you need to type the string WITH the content to be erased
	int length = content.length();
	if (placement > length || placement < backspace){std::cout << "\nError in argument call\n";return;}
	wait(time_delay);
	int b;
	for(int i = 0; i < length+backspace;)
	{
		for(i = 0; i < placement;i++)
		{
			char a = content[i];
			std::cout << a;
			wait(time_delay);
		}
		if(backspace > 0)
		{
			for(i = placement; i < placement+backspace;i++)
			{
				if(i == placement){wait(.15);}
				wait(.05);
				std::cout << "\b \b";
			}
		}
		for(i==placement+backspace, b = placement;i<length+backspace;i++,b++)
		{
			wait(time_delay);
			char c = content[b];
			std::cout << c;
		}
	}
}


i get a nice big fat error if the string is long enough to need multiple lines (without a newline character) or if the string has newline characters which in either case, if the backspace part of the function is supposed to erase the newline char, it fails. I know it comes from the second nested for loop, because that's the backspace type function. Buuuut.... how would i get it to delete a newline character.

Note: if you recommend \r, you have to tell me how to input a checker to see if the previous character is a newline character as otherwise, it will screw up the rest of the effect.
i like your code but have no idea how to fix it :(
closed account (4Gb4jE8b)
hahaha, well go ahead and have it (just don't say you wrote it :P), or if you don't want to use an eraser i wrote this too
1
2
3
4
5
6
7
8
9
10
11
void type(std::string content, double time)
{
	int length = content.length();
	wait(time);
	for(int i = 0; i<length;i++)
	{
		char a = content[i];
		std::cout << a;
		wait(time);
	}
}

which is much simpler.
closed account (4Gb4jE8b)
selfish bump for answer :|
You can't backspace over newlines on the console.

You'd have to use a much more advanced method, using some OS-specific stuff (either directly, via the Windows or terminfo database, or indirectly via NCurses or the like).

BTW, line 32 has an error.
closed account (4Gb4jE8b)
fun. is there anyway to find if the previous character on the console is '\n' and if you're referring to b = placement that's done purposely instead of ==
Topic archived. No new replies allowed.