It seems painfully obvious now. My skull was hurting last night and I did not really think the problem through. Thankyou for the help guys.
Also, because after each action taken, I want there to be a new user input so there is a continual motion to the text based RPG. I need it to recur otherwise I have to continually call the function over and over. I don't know how many inputs I'm going to get, so there we go. So when I recur what I am doing is I am making sure there is never a point after the function is called that you are not reading or giving an input, but I never got round to actually making a point in which it stops. Well yes, my retard went to the max...
however, I am still having a huge issue with this.
If I use _getch() in the syntax function and it recurs there is no issue.
If I just use the single 1 iteration for loop it runs out of memory.
Why is this? Also, cire, that would not work, as I have no idea how many iterations I need. Once a certain thing is true, the recursion stops. Never got round to it, however.
EDIT: I misread that. I thought the 'for( ; ; ){ }' was a for loop that was using a generalization for conditions. I am feeling rather stupid now.
Update: I have edited it slightly, here's what I've done :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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
// Prerequisites.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <conio.h>
#include <cmath>
#include <string>
string input;
string syntaxList[20] = {"look", "suicide"};
string syntaxSay[20] = {"you look at the", "you die."};
bool endGame[20] = {false, true};
bool readyToGo = false;
bool gameOver = false;
string inputYey(string& a) {
cout << "Type something dammet. No more than 20 chars! Or actually write something. Jeez." << endl;
getline(cin, a);
while(a.length() > 20 || a.length() <= 0){
cin.clear();
cin.sync();
cout << "Listen to me -_-!" << endl;
getline(cin, a);
}
return a;
}
string syntax(string& a) {
getline(cin, a);
int c = a.find(" ");
bool done = false;
for(int i = 1; i++; i < 20 && done != true){
string d (syntaxList[i], 0, c);
string e (syntaxList[i], c);
if(d == a){
done = true;
if(endGame[i] = true){
gameOver = true;
}
return (syntaxSay[i] + e);
}else{
done = false;
}
}
return "Syntax error.";
}
int randomthing(){
syntax(input);
_getch();
if(gameOver == false){
randomthing();
} else {
return 0;
}
}
int _tmain(int argc, _TCHAR* argv[]) {
cout << "A'ight!" << endl << "(Any key to continue usually ;) )" << endl;
_getch();
cout << "Yeah I don't suit this all that well. RANDOM TEXT BASED RPG FOR DA WIIIN" << endl;
_getch();
cout << "Say something man! I feel lonely! D:" << endl;
cout << inputYey(input) << "! Are you kidding me! You're boring!" << endl;
_getch();
cout << "anyway, let's get going. you're in a room." << " do something!" << endl; readyToGo = true;
randomthing();
}
|
Notably: no change in the problem.
Another Edit: I'm too stupid for this. Sorry for wasting your time ^_^. I realise the problem.
Another EDIT: Yeah, I fixed that, but it's definitely the for loop now. I realise this after alot of debugs. I can't see the problem with it now.