My best/messiest code so far (work in progress)
etian (31)

So as no one knows, for school I've been working on a tic tac toe game and its pretty fun! I tried doing some coding now but I look through all the code and its completely fine but I guess my home wifi is too laggy. :/

You are viewing a single comment. View All
nt998302 (5)

Good work Etian! Keep coding and you'll keep getting better. Also, just for quick reference, this code clears the screen:
cout << "\033[2J\033[1;1H";

etian (31)

@nt998302 Thank you! I was trying to find how to on the internet.

Highwayman (237)

@nt998302 , @etian guys please do not use that command, it is not portable and requires a video console, which not everyone is going to have. The actual name of that type of thing is escaping me at the moment, but just know that is part of a series of commands that are NOT portable and therefore unreliable. Also can be hurtful for methods like, say, output redirection, (piping, ya know all that good stuff. It will actually see that command - it won’t be invisible to it.)

mwilki7 (556)

Those are called ansi escape codes to modify the attributes of a console.
@etian If that command works for you feel free to use it. Repl isn't switching to Windows any time soon so I don't see how it will break the program.

sanjaykdragon (181)

@Highwayman you are correct, that sequence is not correct.

sanjaykdragon (181)

@mwilki7 a better solution is just to do system("clear");
although that is still not perfect and portable to other systems

Highwayman (237)

@sanjaykdragon nuuuuuu system("clear"); is even worse than ansi codes! That doesn’t even work on repl.it! Really a bunch of \ns is all they need. no need to actually manipulate the screen.

Highwayman (237)

@sanjaykdragon oh, oops, you already said that sorry about that.

Highwayman (237)

@Highwayman really if we are going to be doing any of this, why don’t we just use curses?

sanjaykdragon (181)

@Highwayman what? and spamming \n is way worse... cls/clear works on repl.it

Highwayman (237)

@sanjaykdragon ncurses.h? It makes stuff a bit more portable I think? pcurses for windows too, so it’s not just Unix systems I’m pretty sure.

Highwayman (237)

@sanjaykdragon not really. It does the same exact thing as clearing the screen, just instead of sending out a possibly unknown sequence and literally erasing stuff from the screen, it will just shove that stuff upwards. Besides, I personally just find it better when I have a history of sorts of my input instead of only the current stuff. No need to memorize sequences or include unnecessary headers (this is including cstdlib or ncurses.h, don’t get me wrong)

Highwayman (237)

@sanjaykdragon yeah probably just a typo on my part sorry bout that.

nt998302 (5)

@Highwayman I dislike using the ansi escape codes, but for some reason, the system("CLEAR"); command code doesn't work for me. :(

Highwayman (237)

@nt998302 did you just test it? the thing with system("anything") is that it has completely undefined behavior, so you never really know what you’re going to get and it can be a big security risk apparently, but don’t ask me about that because I’ve just heard that around, I don’t really know how it’s a big security risk.

sanjaykdragon (181)

@Highwayman using system("anything") is only a big security risk if the system command is based on user input

Highwayman (237)

@sanjaykdragon no. Regular commands by the programmer is also a security risk too.

etian (31)

@Highwayman this is all way too advanced for me

Highwayman (237)

@etian maybe. Not necessarily though. Don’t scare your self with strange words, most of it is quite simple.

an ansi escape code is basically anything that starts with '\e['. All it is is if you have a 'terminal emulator' or a 'video terminal', it interprets the stuff after '\e[' as a special command that is has to execute that does something. That thing can be changing the color of the text or changing the position of the cursor in the terminal or clearing the console... all sorts of things, and they all have to do with manipulation of the console screen.

system() is a function defined in the standard c library header (stdlib.h or cstdlib) and all it does is take your string that you pass it and send it as a command to the ... command processor? Idk, all I know is that it produces undefined behavior and that for repl.it it can take bash commands, so maybe command processor just means the shell?

When I say curses, I am referring to a group of header files (ncurses.h,curses.h,pcurses) that we’re created to provide a level of abstraction to manipulating the console and a certain level of portability.

system("CLEAR"); on some systems (hah) will clear the console.

Highwayman (237)

@Highwayman oops I just realized, I’m pretty 'pcurses' isn’t the right name, but whatever it’s close you get my point.