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

Author Topic: Lethn's Programming Questions Thread  (Read 53679 times)

0 Members and 8 Guests are viewing this topic.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #15 on: June 22, 2013, 03:10:48 pm »
I did have a look last night but it can handle numbers fine can't it? Because of course it's unicode and yes, I was planning on replacing that console input stuff with TextEntered :)

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #16 on: June 22, 2013, 07:06:37 pm »

I looked at the TextEntered event documentation and it seems to be suggesting that I need to put unicode in between some brackets, I find this a bit baffling, is there an explanation of why this is and so on that I can have a look at so I don't spend hours getting frustrated over it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Lethn's Programming Questions Thread
« Reply #17 on: June 22, 2013, 08:26:08 pm »
Quote
I looked at the TextEntered event documentation and it seems to be suggesting that I need to put unicode in between some brackets
Hum... ? Could you show the corresponding code instead of trying to describe it with your own words of beginner? ;)
Laurent Gomila - SFML developer

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #18 on: June 23, 2013, 02:18:00 am »
I did say I was baffled :D

 
74  struct TextEvent
75  {
76  Uint32 unicode;
77  };

Its what appears on Event.hpp, I'm also looking at TextEntered, I'm not sure how to use them looking at this code.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Lethn's Programming Questions Thread
« Reply #19 on: June 23, 2013, 08:52:28 am »
Quote
Its what appears on Event.hpp
And? What's your question? Where are these brackets that you mentioned?

Quote
I'm not sure how to use them looking at this code
Don't look at source code. Look at documentation, tutorials and examples on the forum/wiki.
Laurent Gomila - SFML developer

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #20 on: June 23, 2013, 05:41:40 pm »
The Events tutorials explains the TextEntered event pretty good, even for how short it is.  When you poll the TextEntered event it returns unicode # for the character entered.  If you cast this to a string or char it will pop out the other side as that character, for example if you type an 'a' the event will return the unicode '97' which on the ascii table is a lowercase 'a'. 

So the event gives you the unicode, you just have to make a buffer to stuff however many character you want to get into (like if youwanted them to enter a name), cast the stored codes in the buffer however you want, apply whatever switch/if statements to your contents however you want.

That's what i pulled from the tutorial section anyways  :-\

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #21 on: June 24, 2013, 12:40:56 am »
Aha! Yes, read it more carefully now so I know what you mean.

Quote
  The member associated to this event is event.text, it contains the Unicode value of the entered character. You can either put it directly in a sf::String, or cast it to a char after making sure that it is in the ASCII range (0 - 127). 

My only concern with this method is getting this working with loops, which is of course what you need to make your statistics in the games like gold etc. it's easy for me to make something static but I'm probably going to have to mess with this quite a bit before I get it working the way I want.

« Last Edit: June 24, 2013, 12:51:54 am by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #22 on: June 24, 2013, 09:57:21 am »
#include <iostream>
#include <SFML/Graphics.hpp>
int main ()
{

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

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

    line1.setFont( arial );
    line1.setCharacterSize ( 12 );
    line1.setPosition ( 340, 180 );
    sf::Text line2;

    line2.setFont ( arial );
    line2.setCharacterSize ( 12 );
    line2.setPosition ( 240, 80 );

            if ( event.type == sf::Event::TextEntered )
            {
                line1.setString ( "Enter a number:" ) << static_cast <char> ( event.text.unicode );
                if ( event.text.unicode < 128 );
            }




    while (window.isOpen())

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



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

        window.clear();
        window.draw ( line1 );
        window.draw ( line2 );
        window.display();

    }

    return 0;

}
 

Here's what I have planned so far, obviously going to be editing this more and changing things as I go since it isn't working yet.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Lethn's Programming Questions Thread
« Reply #23 on: June 24, 2013, 10:31:23 am »
Seriously, you should really learn C++ first and practice with simpler programs. You're going to waste your time, coming to the forum everyday for new problems or questions, if you try to learn this way.
Laurent Gomila - SFML developer

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #24 on: June 24, 2013, 10:57:13 am »
Reading through stuff now Laurent :D doesn't mean I can't mess with SFML along the way.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Lethn's Programming Questions Thread
« Reply #25 on: June 24, 2013, 11:54:28 am »
Quote
doesn't mean I can't mess with SFML along the way
You can do whatever you want, but you're going to waste your time (and ours), because the only answer to most of your posts is "learn C++".

Look at your last code: you're trying to use the "event" variable before it is declared. Your code doesn't even compile because there's a missing { on the main loop. You don't even know how to indent your code properly so that it is more readable.

You don't need a forum to solve these problems, just learn and practice.

I don't mean to be rude, just trying to help you learn programming/C++/SFML more efficiently ;)
Laurent Gomila - SFML developer

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #26 on: June 25, 2013, 02:20:46 pm »
lolz I'm looking at stuff now and now I know what you mean, the books listed do seem to explain the basics very well so I'll be having a read through of that now. Nice I finally understand properly what the semi-colons and brackets are about >_> the online tutorials are pretty crap :S.

Edit: Oh! I've already found updating loops that work like a game should! Badass! :P
« Last Edit: June 25, 2013, 04:33:42 pm by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #27 on: June 26, 2013, 03:31:29 am »

#include <iostream>
#include <SFML/Graphics.hpp>



int main ()
{

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

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

    int gold;
    gold = 100;

    sf::Text goldtext ( "You have", arial, gold = 12 );
    goldtext.setPosition ( 700, 100 );


    while (window.isOpen())


{
    window.close();
}

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


    return 0;
}


 

I've been looking at some of the books you guys gave me and already it's starting to help a lot, I can even ask questions in a less noobish way! :D Right now I'm trying to combine integers with SFML text, so far I haven't got any errors after some tinkering but the screen just opens and closes without doing anything.

Have I missed something out that's obvious?
« Last Edit: June 26, 2013, 03:34:10 am by Lethn »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #28 on: June 26, 2013, 05:18:01 am »
I'm not sure if it's a joke or not. ??? What do you think window.close(); does? Why is your code worse than the one before?

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #29 on: June 26, 2013, 05:35:24 am »
LOL worse? I'm just going by what I read on the documentation and I didn't realise that you didn't really need it so that's gone now, maybe instead of just saying it's gotten worse you could explain where I'm going wrong? That aside the reason I had the main stuff like this is because that was the only way I could even seem to get it half working, codeblocks puts errors up if I try anything else.


#include <iostream>
#include <SFML/Graphics.hpp>



int main ()
{

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

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

    int gold;
    gold = 100;

    sf::Text goldtext;
    goldtext.setFont ( arial );
    goldtext.setString ( "You have" gold "gold" );
    goldtext.setPosition ( 700, 100 );

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


    return 0;
}


 

Found what I needed, the documentation explains all the possible options for string.

http://sfml-dev.org/documentation/2.0/classsf_1_1String.php#abc989da7f4fb873ab29188d40772ab24
« Last Edit: June 26, 2013, 05:51:53 am by Lethn »