Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with y out put in console  (Read 1364 times)

0 Members and 1 Guest are viewing this topic.

Justbod

  • Newbie
  • *
  • Posts: 9
    • View Profile
Problem with y out put in console
« on: February 08, 2019, 03:12:25 pm »
Hi! If have a really weird problem
The y output is not a number but is :

Jeleki
eleki
leki
eki
ki
i










:AM:am:PM:pm
AM:am:PM:pm

Jeleki is the title of the window.

void display_game(sf::RenderWindow& window, float interpolation)
{
        window.clear();

        for (int x = 0; x < 50; x++) {
                for (int y = 0; y < 50; y++) {
                        //Check if tile should be drawn
                        if (mapdata[x][y] == 1) {
                                sf::Texture tile;
                                if (!tile.loadFromFile("floor_tile_1.png"))
                                {
                                        std::cout << "Error could not load floor tile!";
                                }
                                sf::Sprite tilesprite;
                                tilesprite.setTexture(tile);
                                //int px = x * 40 + 1;
                                //int py = y * 20 + 1;
                                int px = (x - y) * 20;
                                int py = (y - x) * 10;
                                tilesprite.setPosition(px + 500, py + 300);
                                window.draw(tilesprite);
                                //std::cout << "x:" + x << std::endl;
                                std::cout << "y:" + y << std::endl;
                        }
                }
        }

        window.display();
}

If anyone has a clue what is causing this please let me know.
« Last Edit: February 08, 2019, 04:34:45 pm by Laurent »
🧃🦔

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Problem with y out put in console
« Reply #1 on: February 08, 2019, 04:36:41 pm »
Quote
std::cout << "y:" + y << std::endl
"y:" + y points to memory address of literal string "y", plus an offset of y. It is of course invalid and causes undefined behaviour.

What you meant is
std::cout << "y: " << y << std::endl
Laurent Gomila - SFML developer