SFML community forums
Help => General => Topic started by: LucasShadow on December 30, 2011, 04:59:16 am
-
So I am trying to make an application that requires multiple values to be considered. When EventA happens, I want Variable1 to be a certain X number. Then, if statements can check to see if X is the number for that certain if statement, and carry on with a specific order. I am not aware of how to do this exactly, so I tried to do it with strings:
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow App(sf::VideoMode(800, 600), "Test");
sf::String Value1("1");
sf::String Text1("Value1 is active");
Text1.SetPosition(100.f, 100.f);
// Start the game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
if (App.GetInput().IsKeyDown(sf::Key::Up)) Value1.SetText("2")
if (Value1.GetText() == "1") Text1.SetText("Value1 is active");
if (Value1.GetText() == "2") Text1.SetText("Value1 is inactive");
}
// Clear screen
App.Clear();
// Draw the string
App.Draw(Text1);
// Update the window
App.Display();
}
return EXIT_SUCCESS;
}
It doesnt work though. Any suggestions? Sorry if I havent been clear, I am not sure how to express what I want to do :cry:
-
LucasShadow, I'm not sure about C++, but in most languages you cannot compare strings with ==. Why don't you use primitive variables?
int Value1 = 1;
-
Lol, primitive variables completely skipped my mind. Thanks man :)
-
LucasShadow, I'm not sure about C++, but in most languages you cannot compare strings with ==.
In C++, you can compare std::string with ==, but not char arrays. To be exact, "a" == "a" compiles, but compares the addresses instead of the characters.
But if you don't need strings, that's irrelevant ;)