Results 1 to 6 of 6

Thread: Problems with level loading...

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    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.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    thank you
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    This should probably be in the C++ forum.

    Z.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  6. #6
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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
  •  



Click Here to Expand Forum to Full Width