i dont understand this bug, please help me :(

This is a discussion on i dont understand this bug, please help me :( within the C++ Programming forums, part of the General Programming Boards category; my project is to code a maze game and i decided to include some puzzle elements. my group and i ...

  1. #1
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7

    Exclamation i dont understand this bug, please help me :(

    my project is to code a maze game and i decided to include some puzzle elements. my group and i decided that we would have characters that have different properties. for example, pushable characters, characters that you can only pass through once, teleporting characters etc. '$' is supposed to be the character that only allows you to pass through it once, then it will turn into '#' which is an immovable wall. however, when i use gotoxy to move to the $ character, and change it to '#', it does change but the player still can pass through it freely. >.<
    The code for the change is this :

    Code:
    if (move == 'd' || move == 'D')
    	{
    		if (grid[_y][_x+1] == ' ')
    		{
    			gotoxy(_x, _y);
    			cout << " ";
    			_x++;
    			gotoxy(_x, _y);
    			cout << "@";
    		}
    		else if (grid[_y][_x+1] == '$')
    		{
    			gotoxy(_x, _y);
    			cout << ' ';
    			_x++;
    			gotoxy(_x,_y);
    			cout << '#';
    			_x++;
    			gotoxy(_x,_y);
    			cout << '@';
    		}
    		else if (grid[_y][_x+1] == '&')
    		{
    			gotoxy(_x, _y);
    			cout << " ";
    			_x++;
    			gotoxy(_x,_y);
    			cout << "^";
    			_x++;
    			gotoxy(_x,_y);
    			cout << "@";
    		}
    	}
    more info: i have a global char grid[100][100] declared and i used strcopy to copy the text game stages into it. then printing it out with a for loop. help would be greatly appreciated! thanks!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,341
    Your problem will be in code that detects a '#' and prevents the player from moving through it. You have not shown such code, but presumably it is functioning incorrectly.

    Incidentally, in C++, names beginning with an underscore are reserved for use by the implementation (as names that may be placed in the global namespace). That means you should not give variables (or anything else) a name beginning with an underscore. Doing so can mean your code has undefined behaviour.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7
    thanks for the response, i'll change the underscore.

    there is no code detecting the '#'. I didnt put a code detecting a '#' because i dont need it to do anything if the player is moving straight into a '#'. the player will just stay at the current coordinates and nothing will happen to the '#' o.o

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You print a #, but you don't change the thing in the array to # (it's still $), so your future checks won't complain about it.

  5. #5
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7
    hmm, i thought so. thanks!

    now that the problem is identified, how do i fix it x.x

    if im not wrong, i have to go into the copied string, find the character '$', erase it and change it to '#'. but i have no idea how to do that :x
    Last edited by Grey Kliche; 08-09-2011 at 07:08 AM.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Grey Kliche View Post
    hmm, i thought so. thanks!

    now that the problem is identified, how do i fix it x.x

    if im not wrong, i have to go into the copied string, find the character '$', erase it and change it to '#'. but i have no idea how to do that :x
    If you don't know how to do that, then how did you make the maze in the first place?

  7. #7
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7
    strcpy(grid[], "####################$############");
    o_o

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Grey Kliche View Post
    strcopy (grid[], "####################$############");
    o_o
    That ... might work, depending on how you set up your array, assuming you spelled strcpy correctly and didn't actually put the brackets in. Normally we use = to put things into variables.

  9. #9
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7
    it works. i used this to print the stage out:


    Code:
    for (int i=0; i<25; i++) /*Prints copied strings in specified arrays*/
    	{
    		for (int j=0; j<78; j++)
    		{
    			cout << grid[i][j];
    		}
    		cout << "\n";
    	}
    it all works, except for the changing of the $, and other symbols' properties. it changes the symbol on the surface, but its properties remains the same as the previous symbol.
    Last edited by Grey Kliche; 08-09-2011 at 07:26 AM.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need to use = to change the value of a variable. Have you used = before? You put the variable you want to change on the left, and you put the value you want the variable to have on the right.

  11. #11
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7
    i have. i used cout because i thought it worked, but now i find out it only worked superficially. i used
    Code:
    grid[iy][ix] = '#';
    instead and it worked. even though the symbol didn't change, the player cannot pass through the '$' sign now, as though it is actually a '#'. that's nothing a mere cout can't fix! hoho. thanks! this allowed me to proceed with my proj

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    cout is just a print statement, nothing more.

  13. #13
    Registered User Grey Kliche's Avatar
    Join Date
    Aug 2011
    Posts
    7
    yeah! i notice it now. tyvm ^_^

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i dont understand bit
    By joker_tony in forum C Programming
    Replies: 2
    Last Post: 03-27-2008, 12:15 AM
  2. i dont understand this condition
    By joker_tony in forum C Programming
    Replies: 7
    Last Post: 03-22-2008, 01:32 AM
  3. What I dont understand...
    By nomi in forum C# Programming
    Replies: 7
    Last Post: 01-20-2004, 01:00 AM
  4. dont understand VS.NET
    By Qui in forum Windows Programming
    Replies: 6
    Last Post: 10-15-2003, 07:36 PM
  5. So frusterated, and dont understand
    By Blanket in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2003, 08:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21