game loop suport
Sep 7, 2013 at 2:27am UTC
I want to have some varables that can be used throught functions using the extrn comand.
here is my code:
source code:
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <time.h>
#include <stdlib.h>
using namespace std;
void item (){}
void render (){
int con;
extern int var;
const int c1 =1;
if (var == c1){cout <<"hi" ;}
}
void control () {}
int main(int argc, char *argv[])
{
cout <<" ____________________________________\n" ;
cout <<" / |\n" ;
cout <<" | |\n" ;
cout <<" | /\n" ;
cout <<" | /\n" ;
cout <<" | /\n" ;
cout <<" | |\n" ;
cout <<" |=================================|\n" ;
cout <<" | |\n" ;
cout <<" | \\ \n" ;
cout <<" | \\ \n" ;
cout <<" | \\ \n" ;
cout <<" | |\n" ;
cout <<" \\____________________________________|\n" ;
system ("ping localhost -n 10 >nul" );
system("cls" );
loop:
item (); //render items
render(); // render terain
control(); //user input
goto loop;}
data scource file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <cstdlib>
#include <time.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main2 (void ){
srand(time(NULL));
int var = rand() % 4 +1;
string s1 ("`" );
string s2 ("`" );
string s3 ("`" );
string s4 ("`" );
string s5 ("`" );
string s6 ("`" );
string s7 ("`" );
string s8 ("`" );
string s9 ("`" );}
my compiler is DevC++ and it spits out the errors:
[Linker error] undefined reference to `var'
ld returned 1 exit status
C:\Users\%blank%\Documents\%blank%\programs\games\7\Makefile.win [Build Error] [soul.exe] Error 1
Sep 7, 2013 at 4:43am UTC
You said there is to be a variable defined in the scope of the render() function, but haven't ever defined such a variable anywhere else. The one in main2() is local only to that function.
Sep 7, 2013 at 4:56am UTC
Lines 42 - 48: Don't use goto, use a loop.
Sep 7, 2013 at 10:05am UTC
Why are you including <cstdlib> and <stdlib.h>?
Sep 7, 2013 at 1:27pm UTC
so Zhuge should I take out int main2 (void)?
Topic archived. No new replies allowed.