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

Author Topic: Storing and recalling variables within an event  (Read 1499 times)

0 Members and 1 Guest are viewing this topic.

LucasShadow

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Storing and recalling variables within an event
« 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:

Code: [Select]

#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:

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Storing and recalling variables within an event
« Reply #1 on: December 30, 2011, 09:57:43 pm »
LucasShadow, I'm not sure about C++, but in most languages you cannot compare strings with ==. Why don't you use primitive variables?
Code: [Select]
int Value1 = 1;

LucasShadow

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Storing and recalling variables within an event
« Reply #2 on: December 30, 2011, 10:32:05 pm »
Lol, primitive variables completely skipped my mind. Thanks man :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Storing and recalling variables within an event
« Reply #3 on: December 31, 2011, 01:34:22 am »
Quote from: "Tex Killer"
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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: