Jump to content

C++


shadowayex

Recommended Posts

Hello. I'm just starting to learn C++, which doesn't seem as difficult as I thought it would be, since I've been learning PHP as well. Anyways, I'm writing a simple little program that asks for your name, age, and a confirmation to make sure it's right. If it's not, I have it set up so a loop brings it back to the top and you start over. One problem: if you put N, it goes to the top, but doesn't run through right. I'll show you what I mean:Code:

#include <iostream>using namespace std;int main() {    #define start "\n\n\n";    #define end "\n\n\n";    string name, answer;    bool confirm;    int age;    while(answer != "Y") {        cout << start;        cout << "Please enter your name.\n";        cout << "Name: ";        getline(cin, name);        cout << "Please enter your age.\n";        cout << "Age: ";        cin >> age;        while(confirm != true) {            cout << "Your name is " << name << " and you are " << age << " years old. Is this correct?\n";            cout << "(Y/N): ";            cin >> answer;            if(answer == "Y" || answer == "N") {                confirm = true;            } else {                confirm = false;            }        }    }    cout << "Thank you for your cooperation";    cout << end;    return 0;}

Example first time through:

Please enter your name.Name: Cyle DawsonPlease enter your age.Age: 17Your name is Cyle Dawson and you are 17 years old. Is this correct?(Y/N):

If you type N:

Please enter your name.Name: Please enter your age.Age:

It shows up exactly like that, and if you type in anything in the Age: spot, it will continuously bring that exact thing back up, over and over.Is there something I did wrong that caused this error? I thought maybe I needed to unset the variables, but I don't know how to do that. Other than that, I have no idea what's wrong. This program isn't really important, but the knowledge gained from it is, so in the end this is kind of important that this problem is fixed. Thanks to anyone who answers.

Link to comment
Share on other sites

  • Replies 53
  • Created
  • Last Reply

You never reset confirm to false, so it doesn't enter the second while loop the second time. I'm not sure if getline or cin doesn't wait if the variable already has a value, I don't think that's the case though. It should wait for input regardless. When I get back to my compiler I'll double-check.

Link to comment
Share on other sites

Resetting confirm to false fixed the infinite loop problem, but it still shows up in the above format whenever I try "N". If i change getline(cin, name); to cin >> name;, it works. But if I do that I can't have spaces >_<. So the problem evidently is getline(cin, name);.

Link to comment
Share on other sites

You might just need to reset name.name = "";getline(cin, name);Actually, I think I'm remembering something from school. Using the >> operator doesn't extract the delimiter, so when you type "17\n" for the age it will extract the 17 but not the line break, so I think the next call to getline sees the linebreak on the input stream and ends. So after reading using >> you need to clear the input buffer. You can use cin.ignore() to ignore the next character in the input buffer (the line break), or something like cin.ignore(10) to ignore the next 10 characters, or cin.ignore(20, "\n") to ignore the next 20 unless it finds a line break.

Link to comment
Share on other sites

Nope, no change. Good idea though. Hmm... if I were more experienced at this, I could attempt to provoke an idea, but I don't know why getline() is acting up. Logically it should work >_<. Could it be my compiler? I use Dev-C++ by bloodshed.net.

Link to comment
Share on other sites

i think ive had this problem beforei think this was my solution:try not to put the answer as a string make it You are (age) years old. Is this correct (Y/N)and then put the answer as a bool i thinkthen do a case switch(note i forget the syntax, im sure google has a great example)case 'Y':case 'y: break; (or w/e)case 'N':case 'n': goto: (then specify a place using the goto statement. )I am not great at c++ if your thinking im a complete idiot. I tried self teachign myself but apart from 1 year of simple stuff and a book i went like 9 chapters in out of 35 well there you go..oh look at the time im rambling on sorry

Link to comment
Share on other sites

Did you try just cin.ignore()? You only want to ignore 1 character, I was just giving examples of how to use cin.ignore.

cin.ignore(10) to ignore the next 10 characters, or cin.ignore(20, "\n") to ignore the next 20 unless it finds a line break.
try not to put the answer as a string
String is the only option. It's not an integer, floating point number, character, or boolean, it's a string.
and then put the answer as a bool i thinkthen do a case switch
bool is true/false only. If you're switching over "Y", "y", etc that's either a char or a string, bool is only true/false. Also, for future reference most programmers these days try to avoid using goto, if you've ever seen a program that has goto statements sprinkled around it gets very difficult to try and follow the logic. If you want to really have fun, one language has a "come from" statement.
Link to comment
Share on other sites

This code works with cin.ignore:

#include <iostream>using namespace std;int main() {	#define start "\n\n\n";	#define end "\n\n\n";	string name, answer;	bool confirm;	int age;	while(answer != "Y") {		cout << start;		cout << "Please enter your name.\n";		cout << "Name: ";		getline(cin, name);		cout << "Please enter your age.\n";		cout << "Age: ";		cin >> age;		confirm = false;		while(confirm != true) {			cout << "Your name is " << name << " and you are " << age << " years old. Is this correct?\n";			cout << "(Y/N): ";			cin >> answer;			cin.ignore();			if(answer == "Y" || answer == "N") {				confirm = true;			}		}	}	cout << "Thank you for your cooperation";	cout << end;	return 0;}

This page has a good explanation why you need to use cin.ignore in this case:http://www.augustcouncil.com/~tgibson/tutorial/iotips.htmlCheck out the rest of that page also, including the part about reading in numbers directly.Thanks for giving me a reason to bust out the EeePC!

Link to comment
Share on other sites

Ha, you're welcome. Although I don't know what that is, I'm glad I could help you while you're helping me. I'm surprised at myself that I basically understand why the cin.ignore was needed. It's because the newline is considered input and is taken into the variable instead of letting you type something right? I hope that's right. That's at least what I got out of it. But I do understand that the newline was the problem so the cin.ignore() would ignore it. An issue with mixing getline and cin >> var. Thanks for the article. I'll be using it along with cplusplus.com to help my learning. I'm hoping that I'll learn how to store information into files soon, because I think I could build a nice little text based game simulation out of this if I could have a way to save. But I should just take it steps at a time and learn things in order, although I'm quickly discovering that a lot of what I'm "learning" is how to do in C++ what I already know in PHP. It's kind of exciting, yet boring.

Link to comment
Share on other sites

That's right. One of the things you'll become familiar with in C++ is streams. On the top of the code you include the iostream library, that is the standard input/output stream library for C++. That's what makes cin and cout available. Both cin and cout are streams, cin is the standard input stream (keyboard) and is the class istream, and cout is the standard output stream (monitor) and is the class ostream. You can also use fstream for files, it's the same thing. The << and >> operators read and write to and from a stream. When you do this:cin >> varnameYou are reading a value from the cin stream and saving it in varname. When you do this:cout << varnameYou're writing the variable to the cout stream. So one of the things about using the >> operator with cin is that it will only read what it considers a "word", so it stops reading whenever you get to whitespace. But it leaves the whitespace on the input stream still, it doesn't consume it. So when you go to use getline after that, the whitespace that cin left on the input stream is the first thing that getline reads. If that's a line break (or whatever getline is looking for), then it will just quit with that input. Getline does consume the character that it stops at, unlike cin.To show that a little bit more, run that program again and type a name, then for the age type a number, then a space, then Y, and hit enter. cin>> will read the number from the input stream, see the space, and end. It will leave the space on the input stream, the "Y", and the line break. When cin>> gets called in the loop to get answer it will strip the space (cin>> ignores all whitespace at the beginning of the stream, which is why if you use cin>> repeatedly it's fine because it keeps stripping the last thing it stopped at) and then read the Y, stop at the newline, and the program will immediately quit without you confirming. Likewise, if you type a number then a space then N for the age the program will loop around again without waiting for an answer.When you read and write to files, you'll find that after opening the stream to the file it's the same thing.your_ifstream >> in_varyour_ofstream << out_var

although I'm quickly discovering that a lot of what I'm "learning" is how to do in C++ what I already know in PHP
That's a lot of what programming is, you need to learn the basic concepts that you can apply to any language (see the quote in my sig from the inventor of C++). If you know how to use files or a database or whatever then all you need to learn is how a certain language does those things. If you understand what an array or hash table or binary search tree or bubble sort is then you can use those concepts in whatever language you know the syntax for. You'll also figure out that PHP lets you get away with a lot of stuff that other languages like C++ are more strict about. PHP pays for some of those things with speed, if you write some code to open a file and write a certain piece of text to it you'll find that the C++ code is a lot faster than the PHP code is (you can put code in the programs to record the start and end times). Learning C++ will expose you to a lot of concepts that you don't have to deal with in PHP. Learning C will expose you to even more. If you learn those things you'll find that all the code you write, even PHP or Javascript code, is more efficient and less buggy because you're paying more attention to how the computer actually executes your program. A lot of people push things like validating your HTML pages against a strict doctype and then they go and write sloppy PHP code. If your PHP code shows error messages, even just notices, when you run it with maximum error reporting then it needs to be fixed. You'll get used to that type of thing in C++, if you try to use a variable that hasn't been declared yet then the program either crashes or doesn't even compile in the first place, where with PHP you would just get a notice while it silently creates the variable before using it.
Link to comment
Share on other sites

Wow, a lot of information. I noticed that C++ is a lot more strict about the code, but since I used strict error reporting with PHP anyways, I was kind of used to errors with variables and whatnot. My compiler actually won't let me compile the code is there are any errors whatsoever. It's really nice because it teaches me to write nice, neat code, and I will apply that to my PHP programming as well. I'm starting to like C++ just as much as PHP, except one little thing. The tutorial at cplusplus did not cover saving to databases. Is there a way to save stuff to a MySQL database, or any type of database for that matter? If not, I was thinking about using fstreams to save arrays into files and use those as "databases" (if you know what I mean, if not, I can try to clarify with an example). But a friend and I have the perfect idea for the structure of a game, we just need a way to save information. We also have no idea about making animations for it or anything close to any of that. We have a lot to learn, but I think with support when needed, and my tendency to learn quickly, we'll do great.But first, is there a way to save to databases of any kind? If it's not MySQL, I can download the needed program. I would prefer MySQL though because I'm already familiar with it and I have it on my computer already.

Link to comment
Share on other sites

Files work as a storage medium. If your game is a single-player game, it would be better to use files so that you don't have to distribute a database with your game. If you're making a game server or something for a website where more than one person is going to be playing at once and the game is hosted in a central place, then you would probably rather use a database. I've actually never had to use a database with C++, I've always saved to files. That's what normal programs do though, when you save or load data you normally read from a file, anything from a text config file to a binary save game file.

Link to comment
Share on other sites

Well the game will eventually be an assassin MMO, so it will eventually need databases. I'll start googling around and see about using databases. For now I probably could use files, since we're only starting to develop it. If you see or read anything, let me know. I'll probably be back with more problem. In fact, count on it :). Thanks for your help so far.

Link to comment
Share on other sites

Ok, I can indeed use mysql in C++, but I don't know how to connect to a mysql database through C++, so yeah. I tried arrays, but it's too complex for me to understand >_<. I'm not smart enough to even begin this project.

Link to comment
Share on other sites

Arrays are actually pretty easy. If you understand what a variable is then you can understand what an array is. A variable is just a name that points to a certain location in memory. So if you have a variable declared like "int i", then i is an integer variable. If you're on a 32-bit system, then i points to a 32-bit block in memory with a specific address. On a 32-bit system you would get an 8-byte address, like 0x01234567. So when you refer to i in the program the computer will look up the value in whatever address in memory was assigned to i. You can think of the memory location as a mailbox and the variable name is a shortcut to point to it, like a street address points to a physical house.An array is the same thing, except it's more than one variable. An array has both an address and an offset. When you declare an array like this:int arr[10]Then you have reserved space in memory for 10 integers, but arr still points to only a single address, say 0x01234567. Since this is an array of ints, then the offset will be whatever the size of an int is, like 32 bits. The offset is what you write in brackets when you refer to array elements. So arr[0] would point to the base address plus an offset of 0, so arr[0] would be stored at 0x01234567 in memory. If you refer to arr[1] then the location in memory is (base + (offset * size)). Since the int size is 32 bits, or 8 bytes, then the location of arr[1] would be (0x01234567 + (1 * 0x8)), or 0x0123456F. arr[2] would point to (0x01234567 + (2 * 0x8)), or 0x01234577. So all the array is is a pointer to the first element in memory with space reserved for the other elements behind it. That's why in C and C++ you have to declare how big you want the array to be, so that it can allocate that much memory. With PHP the array elements aren't necessarily stored next to each other in memory, so you can dynamically change the array size. C and C++ map more directly to the hardware, so you're interfacing with the memory more directly. That's also why arrays start at 0 instead of 1, because with an offset of 0 it just points to the first location in memory, the base address.So an array is just more than one variable that all have the same name. The C++ array library just contains functions that act on arrays to make working with them easier. For multi-dimensional arrays, it's pretty much the same thing. If you declare an array like this:int arr[3][10]Then you've declared an array with a total of 30 elements, you can visualize a 2-dimensional array as a table or spreadsheet with rows and columns. That array would have 3 rows of 10 columns. In memory though it's still a continguous chunk of 30 32-bit integers. So when you change the last number:arr[0][0]arr[0][1]arr[0][2]then you're still adding 32 bits to the base address like with a 1-dimensional array. When you change the first number you're adding the entire size of the second array, so since the second dimension has 10 elements then changing the first number adds 320 bits to the base address. If you had a 3-dimensional array:int arr[3][10][10]then changing the last number adds 32 bits, changing the second number adds 320 bits, and changing the first number adds 3200 bits. That array has a total of 9600 bits in storage, or 1200 bytes, or 1.17KB. If you write a program that declares an array like this:int arr[10][10][10]; // 10*10*10*32 = 32000 bits = 4000 bytesAnd write it so that it declares the array and then pauses, you can open up Windows task manager and check that it's taking up about 4KB of memory, plus whatever overhead Windows uses to run a program.If you want to keep studying C++, you should probably get a book. The 4th and 5th books on this list should be pretty good:http://oreilly.com/pub/topic/cprog?page=bestsellingYou can use this site to check which textbooks some of the bigger universities use in their computer science programs:http://www.comparecurriculums.com/Once you understand C++ in general, you'll want to look into graphics. If you use OpenGL then you can have Linux support also, if you have DirectX then it will only work on Windows. There is quite a bit of OpenGL code online. This is one of the better sites for OpenGL information:http://nehe.gamedev.net/Here are some OpenGL demos:http://www.apgardner.karoo.net/gl/demos.htmlHere's a tutorial about moving the camera:http://gamecode.tripod.com/tut/tut03.htmYou're going to need to understand C++ before you start on the graphics though. OpenGL is hard enough to understand and learn (unless you like multiplying and adding 3-D matrices of numbers), if you're still trying to learn C++ when you're learning OpenGL then you're not going to have much fun.If you're looking for a college, Bjarne Stroustrup, the inventor of C++, is the chair of the computer science department at Texas A&M, and Bryan Kernighan, the inventor of AWK, AMPL, and the co-author of the book on C, is a professor at Princeton. If I go back for a master's then A&M is probably top on my list, it would be pretty cool to learn programming from someone like Stroustrup.

Link to comment
Share on other sites

Matrices >_<. College Algebra just keeps haunting me... I just took that last year (my junior year in high school). This year I'm taking Advanced Math (mostly Trig) and Calculus for my math stuff. Physics is more science that math, but I'm taking that as well. I'm sure all those classes are going to help. Anyways, I'm going to attempt to break down my game plan (no pun intended). This is moreso for my help of getting things straight, but also kind of to let you know what to expect in my questions.1) Write a C++ exe that will be the structure of the game. For this I have to find a way to store data effectively. I have confirmed mysql and be done in C++, but I'm not sure how to connect to my existing MySQL installation (through WAMP) and all that good stuff. I'm googling it, but getting nowhere. If I can't figure that out, I will try saving stuff in txt files (storing them in arrays and storing the arrays in txt files maybe. That's the only idea I have). I'll write up the stuff I need to save player information and "CPU" character information. I was thinking if I were to use files, I'd have to make a file for each probably. Then figure out how to import and export them as needed (this is starting to sound overly complex). Then comes the fun part, the actual interaction between characters (for now player to CPU, because I do not know how to set up a server for this, nor do I know where to learn). Once all of that is complete, I'll basically have a text-based game. Yay!2) Learn about OpenGL and figure out how to link the things I make to the C++. This will really test me as I am new to both languages, and the concept of doing something even remotely similar to this. But this also excites me the most because this will bring an actual visual model to all my hard work. I have no prior knowledge to OpenGL, besides knowing it exists and that it is something to do with graphics. I did not know it's a programming language that actually creates graphics though. That really excites me, but looks extremely complex. But if I get it down, I will be so happy and proud.3) When everything is said and done, I'll have to learn to set up a server for this (at least for player to player testing). This sseems like it might be the most complex of all, because I do not even remotely know how this can be done. I don't suppose there's a C++/OpenGL version of WAMP out there is there? :) Anyways, from there I can migrate from a single player game to an MMO, which managing that will definitely test my skills.I know all of that may be even years down the road, but I believe someday it will work and I'll be so proud. I'm hoping I can get some form of functionality to it before college, that way I have something to show my professors and the college people to show how serious I am about this stuff. Once again, I see lack of money will begin to hold me back at this as well, but I'll make due with what I can get. I have my mind set on a few books for a few different languages. Also, I plan on running a website for the game of course, which will be helpful to my programming practice as well, since PHP and C++ syntax is indeed similar. Concepts are close to the same, but with different names. Kind of nice knowing PHP concepts when trying to learn C++.As for college, I've looked at MIT as well, since someone from my school that I look up to is going there. But it seems like a hard school to get in to. I'll look into Texas A&M as well. I also have ISU (Iowa State University) to fall back on, since my grandma went there a few different times for a few different degrees (including a computer science one no less. Ironic, huh? She used to program using really old languages on the Iowa State Government's computer system back when computers where rooms. She told me what RAM used to be. I'm not sure if you know, but it sounds awesome. I wish I could've seen it). Anyways, I'm trying my best to get everything going in the right direction, but I'm only 17. I'm still trying to do all this and maintain my social life. I run a club for some local kids, along side my girlfriend and a few good friends. I think I'm taking too much of a load on my shoulders >_<.

Link to comment
Share on other sites

Algebra... yeah. One can wonder why programming colleges often accept students in a math exam rather than a programming exam of some sort. Memory calculations like the above explain why. Fortunatly, even an algebra dummy like myself can learn programming (at least to a decent extend) as long as it undestands arithmetic progressions, combinatory and probabilities. And those are a breeze.I thought OpenGL is a C++ library... now (after making a Wikipedia check to make sure I was really wrong) it seems it's a cross-platform API (think "DOM") for graphics that happens to have a C++ implementation as well as in other languages. Still, this means you're not learning a "language" - you're learning an API. If you know C++ (and by the looks of it, you have a decent understanding already), you should be able to quickly get something out of OpenGL. Once you get that something, I'm betting you'll quickly get to the point of where you can do anything that can be done by a single person.I'm not sure I understand how exactly is your game going to work though. Do you want to make a "World Of Warcraft" like MMO (clients download an executable that casts graphics and all on their PC, getting the player data from a server), or do you want to make a web based game (clients register on a web site and do everything from their browser).I'm guessing it's the second, since we're talking about OpenGL and the like, but I'm not sure how you plan for the client-server relationshop will proceed. I mean, you're contradicting with yourself.You need a MySQL C++ API (the documentation is here btw) if you want the program to connect to the DB server directly. This however seems unwise to me. It's like trusting JavaScript (a "client") to have the last word as to what should be in a DB. This means that player X may easily appear for other users to be having an infinity of everything, when in reality, he hasn't really earned it - he has just cast a query to the DB server.What you should really do is use socket connections (ala "PHP") to connect to your server on a custom port of your choise. You can then transmit data from and to the client in a state-preserving fashion. You could also cast HTTP request, but since HTTP is stateless, you'll have a lot of performance problems if you do that. The point is that the server will verify incoming data, and make a decision as to whether it should be written to the DB, or if it should return an error.The server itself can be written in any language. Heck, even in PHP. However, note that to make the server "resident" (initialize once, keep state) it must be registered as a daemon, and that can happen only on Linux. In addition, you need to fork the daemon to ensure that it will work good for multiple players, and this presents a new set of possible problems to watch out for.To do the same in Windows, you need to use Services, but I'm not sure how the things with them go (truth be told, I haven't made anything in Linux either, but at least I can imagine it from the documentation - not the same with Services).I believe constructing the server will be the hardest part, no matter in which language you write it, exactly because of those things.

Link to comment
Share on other sites

Ok, the idea of the game is something like WoW, an MMO that people download. But I'm going to have a website for the users to communicate through as well. But the game itself is strictly going to be a downloaded game. If OpenGL won't work for this, tell me now before I start trying to use it for this. Now, what I want is for this downloaded game to connect to the server database and get the information through queries, much like you can do with PHP. I know nothing about API (or at least I don't think I do, considering I have no idea what it is, I've just seen the letters before). All I know of C++ is how to do the operations and everything and write different programs and whatnot using the same principal ideas I use in my PHP applications, which are vast. But without being able to connect to a database my skills are extremely limited because almost every one of my PHP applications have been run with databases. I know how to save to files and everything, that's not hard. I would just rather use databases. Now, I didn't think this would be so tough to figure out, considering how easy it is for PHP to connect to a database. It's included in the vast number of functions for PHP. I'm going to take a wild guess and say that with C++, it's not that easy. I don't know much about programming and such, as PHP is the closest to programming I've ever done, and like I said, it's been powered with PHP functions and databases. As for the server, I'm stuck there I guess because I don't have Linux. I tried to install Linux on a computer once and it did not work. I don't exactly know what I'm doing when installing Linux, nor do I know where to learn how to install Linux. I don't have the money to buy a commercial Linux distribution that comes with instructions and whatnot, so yeah. If I were to install Linux, I would like to install it on this computer,but keep my Windows as well, because there's some things I have that are Windows only. Anyways, that will have to wait I guess. I hope this clarified a little bit.

Link to comment
Share on other sites

If OpenGL won't work for this, tell me now before I start trying to use it for this.
You can use OpenGL (Open Graphics Library) to render the graphics, but it won't help you with connectivity.
I know nothing about API (or at least I don't think I do, considering I have no idea what it is, I've just seen the letters before).
API = Application Programming Interface. Basically it is an interface that you can use in your programming language to access and use a application (like OpenGL). The C++ MySQL API, therefore, allows you to interface with MySQL using C++.
Now, I didn't think this would be so tough to figure out, considering how easy it is for PHP to connect to a database. It's included in the vast number of functions for PHP. I'm going to take a wild guess and say that with C++, it's not that easy.
Did you read the C++ MySQL API's documentation? Looks very simple to me (and alot like mysqli in PHP).
As for the server, I'm stuck there I guess because I don't have Linux. I tried to install Linux on a computer once and it did not work. I don't exactly know what I'm doing when installing Linux, nor do I know where to learn how to install Linux. I don't have the money to buy a commercial Linux distribution that comes with instructions and whatnot, so yeah. If I were to install Linux, I would like to install it on this computer,but keep my Windows as well, because there's some things I have that are Windows only. Anyways, that will have to wait I guess. I hope this clarified a little bit.
Installing Linux, even dual-boot, is very simple. Ubuntu server edition is a good distribution with a great support community, ask them. But Windows can run servers as well, just that Windows server costs a lot.
Link to comment
Share on other sites

The point I was trying to make is that you should NOT use C++ to connect to the DB. At least, not in your game executable (the one with the graphics and all).Instead, your game executable should connect to the server in another (specially designed for the purpose) fashion, and ask the server to do the certain things. The server must then not only do those things, but verify if they are legal before doing them.Think of your game executable as your client side stuff (XHTML+CSS+JavaScript). And think of your server as your server side stuff (Apache+PHP+MySQL).Allowing your game executable to connect directly to your MySQL DB is like letting JavaScript interact with MySQL. In the case of JS+MySQL, the case is even worse as the code (the MySQL username and password) are visible in plain text, but the reality is that any applications' network comminucation can be viewed and altered unless encrypted*. You may not need encryption, but you still need to make sure you're not allowing plain DB connections. Instead, you must only allow previously verified connections. In the web world, this would mean that you must filter the input with PHP and then submit the clean query to MySQL.OpenGL is one way to do graphics. Direct3D is the other main competitor. Both are good as far as I can tell, though I'd go with OpenGL because it's cross platform, meaning that if you someday decide to rewrite your game in another language for whatever reason, you could do so easily.As for what an API is. Synook gave you the raw definition. If you want a simpler one - think of an API as a set of class methods, properties, functions and constants for doing a certain thing. For example, PHP has a DOM API that follows the W3C DOM specification for XML manipulation. Other languages have a DOM API as well. What makes it "cross platform" is that all method names and properties are the same and they do the same things in all languages. The only thing that may differ are the class names (PHP prefixes them with "DOM", other languages with "XML", "DOMXML", others place it in a namespace, etc.) and the basic syntax by which you access the methods and properties (PHP uses "->", JS uses ".", etc.).The MySQL(i) extension functions are an API by themselves since they are used in combination to interact with a MySQL DB, but they are not cross platform like DOM, because they were designed specifically for PHP. MySQL has other APIs for other languages, among which is C++.* Doing encryption decreases performance and makes the application harder to implement and maintain. It's wise to do encryption on top of an existing non-encrypted protocol, rather than trying to invent something new. So... stay away from this until you have the game working.

Link to comment
Share on other sites

Ok, so if not using C++ to connect to the database, what do I use? I don't want to do encryption. I'd rather have a secure method that is simple enough for me to grasp. Since the game itself is totally client form, and as far as I know PHP is web scripting only, PHP won't work, right? What choices do I have and what would you suggest?I'll look into the Linux you suggested. If I can get it, that would be great. I've always wanted to work in a Linux environment. I heard it's matching the capabilities of windows, and since it's free, it would seemingly trump windows.

Link to comment
Share on other sites

As I said, you can use any language to construct the server. C++, PHP or whatever you can set up and running as a server application.You use nothing on the client side to connect to MySQL. Using the client side, you just connect to your server. Your server application then connects to MySQL. If you don't connect to MySQL, your data doesn't need to be encrypted, so as I said, don't bother with this.The way you're currently thinking about it is:Client --- connects to ---> MySQLClient <--- receives data from --- MySQLI'm suggesting a slightly more complicated approach for the sake of the game's security, portability and maintainance:Client --- connects to ---> Server applicationServer application --- connects to ---> MySQLServer application <--- reveices data from --- MySQLClient <--- receives data from --- Server applicationIt's wrong that PHP can only be used for web applications. PHP scripts can be executed from the command line the same way you execute C++ console applications. And with packages like PHP GTK you can even create desktop GUI applicaitons.In Linux, you can register console applications to always remain opened and receive input from a certain port. In Windows, it's a little more trickier than that, though doing something similar is still possible (what do you think Apache and MySQL are REALLY made of?).

Link to comment
Share on other sites

Basically, the client I'm building is like a "browser", right? The "browser" needs to connect to the server application and have the server application do everything, just like building a website. Am I right?If so, is it possible to have my client connect to an existing WAMP installation on a server I already have and create a new folder in that to hold all of the files needed to run the game, then have the client communicate with my server exactly like my website testers use their browsers to connect and communicate with my website files?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...