|
-
Jan 7th, 2003, 06:26 AM
#1
Thread Starter
Frenzied Member
Problems with level loading...
Hi!
I am programming a breakout game, but cant seem to get the leve loading working....
loading code:
Code:
int LoadLevel(int level){
char File ="level.dat";
char s[32];
Num = fscanf(File, " %s %d %d ", &level_x, &level_y);
if(Num != 2){
return false;
}
return(1) ;
}
File format
Code:
<x_coord> <y_coord>
Level file:
Code:
1 10
5 20
10 30
15 40
20 45
25 50
30 55
35 60
40 65
45 70
50 75
55 80
60 90
65 100
70 110
75 120
80 130
85 140
90 150
95 160
100 170
105 180
110 190
115 200
120 210
I get the following errors:
:\Game Programming Projects\CrazyBalls 2\main.cpp(212) : error C2440: 'initializing' : cannot convert from 'char [10]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\Game Programming Projects\CrazyBalls 2\main.cpp(215) : error C2664: 'fscanf' : cannot convert parameter 1 from 'char' to 'struct _iobuf *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
F:\Game Programming Projects\CrazyBalls 2\main.cpp(534) : warning C4244: '=' : conversion from 'const double' to 'int', possible loss of data
F:\Game Programming Projects\CrazyBalls 2\main.cpp(537) : warning C4244: '=' : conversion from 'const double' to 'int', possible loss of data
Error executing cl.exe.
CrazyBalls 2.exe - 2 error(s), 5 warning(s)
Hope you can help me correct my errors....
Last edited by CyberCarsten; Jan 7th, 2003 at 06:30 AM.
-
Jan 7th, 2003, 04:14 PM
#2
Code:
int LoadLevel(int level) {
char File ="level.dat";
char s[32];
Num = fscanf(File, " %s %d %d ", &level_x, &level_y);
if(Num != 2) {
return false;
}
return(1) ;
}
Ok, let's see.
char File = "level.dat";
should be
const char *File = "level.dat";
Then you have to open the file.
FILE *fIn = fopen(File, "rt");
This handle you can pass to fscanf.
Num = fscanf(fIn, " %s %d %d ", &level_x, &level_y);
And the %s you pass is DEADLY!
It should be
Num = fscanf(fIn, "%d %d ", &level_x, &level_y);
Finally, you're mixing data types.
return false;
...
return 1;
The function is declared to return int, so don't return the bool value false, return 0.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2003, 05:36 PM
#3
Thread Starter
Frenzied Member
thank you
-
Jan 7th, 2003, 10:24 PM
#4
Frenzied Member
This should probably be in the C++ forum.
Z.
-
Jan 8th, 2003, 04:29 AM
#5
Maybe, but it's still a game issue.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 8th, 2003, 09:53 AM
#6
Frenzied Member
Originally posted by CornedBee
Maybe, but it's still a game issue.
Its formatted file IO. It could be anything =).
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|