SFML community forums

Help => General => Topic started by: Lethn on June 20, 2013, 02:19:06 pm

Title: sf::Text not declaring properly?
Post by: Lethn on June 20, 2013, 02:19:06 pm
I wonder if I should just make a thread for all my queries here to be honest :P I'm trying not to spam the forum but I've run into annoying problem with sf::Text. I thought I'd try it out since I'm still working on the other problem in my head but I found that no matter what I try the command isn't declaring my objects properly.


#include <Iostream>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

int main()
{

    sf::RenderWindow window(sf::VideoMode( 800, 600 ), "C++ Programming Test");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )

    sf::Text lineone;

    lineone.setFont( arial );
    lineone.setString ( "SFML Text is working!" );
    lineone.setCharacterSize ( 12 );
    lineone.setPosition ( 400, 300 );





    while (window.isOpen())
    {

    sf::Event event;
    while (window.pollEvent(event))


{
 if (event.type == sf::Event::Closed)
 window.close();
}

        window.clear();
        window.draw ( lineone );
        window.display();

    }

    return 0;

}

 

Quote
|15|error: 'lineone' was not declared in this scope

It's clearly complaining about me naming my text but the problem is I can't see where I've gone wrong, I think I need a fresh pair of eyes to just have a look over it. I've probably missed something really obvious like a typo or the way it's laid out.
Title: Re: sf::Text not declaring properly?
Post by: Sqasher on June 20, 2013, 02:31:54 pm
Your lineone is in the scope of the if condition.

if ( !arial.loadFromFile ( "arial.ttf" ) )
{ }
sf::Text lineone;

that should fix your problem.
Title: Re: sf::Text not declaring properly?
Post by: Lethn on June 20, 2013, 02:36:41 pm
ahhh okay, so it's okay to leave the empty brackets in there, thanks.

Edit: Yep, working now.