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

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

0 Members and 1 Guest are viewing this topic.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Lethn's Programming Questions Thread
« Reply #30 on: June 26, 2013, 12:38:59 pm »
Laurent should really consider opening up a separate C++ help forum. People probably understand "Help requests that are not related to a specific module" in an all too general way. It should still be related to SFML in some way.

Also... did you have a look at the FAQ? Here is a link in case you can't find it: https://github.com/SFML/SFML/wiki/FAQ#wiki-grl-learn

As time passes, people are going to get more reluctant to help you considering you chose the head through the wall method of getting things done. This thread has been going on for a week and in that time instead of trying all possible combinations of code to make the compiler shut up and build you could have read an online introduction to C++ like the one at http://www.cplusplus.com/doc/tutorial/ among many others. Don't interpret the lack of replies you will be getting here as being unhelpful, it will be for your own good.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #31 on: June 26, 2013, 02:59:37 pm »
That's actually the most helpful post I've seen here yet Binary, I didn't know about that faq and it's very helpful because now I know all the specifics of what I need to learn rather than just staring randomly at C++ books and only getting bits of knowledge I can use for SFML, thanks for the links.
« Last Edit: June 26, 2013, 05:08:31 pm by Lethn »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #32 on: June 26, 2013, 09:38:05 pm »
That's actually the most helpful post I've seen here yet Binary, I didn't know about that faq and it's very helpful because now I know all the specifics of what I need to learn rather than just staring randomly at C++ books and only getting bits of knowledge I can use for SFML, thanks for the links.

This should tell you that there are some deeper c++ issues than you think.  All the good C++ books I've read have always been laid out in such a way that by starting from Chapter 1 and progressing linearly through it I will learn everything a beginner needs to know about C++.  Books are generally laid out in a way that you start at the beginning and learn the building block in an order that brings their natural evolution to fruition.  If you are just turning to random pages and subjects trying to find one small piece of code to fix what you have wrong then you are doing it wrong.

Seriously just sit down with a book, ONE book, and start reading and doing the examples it has from the start to finish.  Once you're done adding SFML to a project will be easy-peasy.

Think of it this way, if you are having problems understanding what {} and ';' do (which groups parts of code and is the end of line syntax delimeter) and don't know how to properly manipulate strings yet
 goldtext.setString ( "You have" gold "gold" );
(This line is all kinds of wrong).  Then what makes you think that doing anything further down the road such as managing States, inventory, combat, creating and managing all your entities, pointers, new/delete(if you have to), vertex array usage, proper texture management is going to be any easier to understand or even have a 'fix' that you can find in a book?

At my last university I was at we took a year of Java and 2 years of C++ before they even let us touch other libraries for them.  Just straight basic Java and C++ was all I needed to learn the fundamentals and libraries seem like a snap now.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #33 on: June 26, 2013, 11:23:00 pm »
I get what your saying Hatchet :D I definitely like the look of C++ primer books wise so I'll probably just get to reading through all that properly, what I like about it is that it points at the different bits of the code ( quite literally ) and properly explains what it all means, too often, especially with the tutorials you get the people who write them trailing off or just outright not bothering to mention completely basic things to you.

I guess I'm just getting frustrated as well because I honestly don't have too difficult a time getting this kind of stuff to work with the console but when it comes to SFML it all goes to hell. I'm going to hurry up and learn C++ properly so I can get to making games :D so far looking at C++ is helping me get a decent idea of things, I just need to know what actually works.
« Last Edit: June 27, 2013, 12:00:08 am by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #34 on: July 02, 2013, 11:59:58 pm »
I'm just thinking it through now after reading through the book and some stuff I found on google ( I'm learning all the different vocabulary properly now thanks to reading through C++ and the SFML book :D ) am I right in thinking that string buffers and insertion operators are the main thing you need for displaying integers in text? I found some very helpful answers when I changed the keywords I searched for, this is the sort of thing I've been looking at for those who are curious, should also help the vets know if I'm on the right track.

http://gamedev.stackexchange.com/questions/43431/how-to-display-text-and-numbers-in-sfml-2-0
« Last Edit: July 03, 2013, 12:02:55 am by Lethn »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #35 on: July 03, 2013, 01:36:47 pm »
am I right in thinking that string buffers and insertion operators are the main thing you need for displaying integers in text?
You probably mean string streams, there are no string buffers in C++. Yes, the std::stringstream class allows you to convert from and to strings.

C++11 also offers the std::to_string(), std::stoi() and similar functions -- these are helpful when you only want to convert a single value, instead of concatenating multiple ones.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #36 on: July 03, 2013, 02:13:07 pm »
lol! Still got lots to learn, thanks for the heads up, one thing I always find is a real piss take no matter what profession you go into they all have their own vocabulary and often forget to explain it all to you >_<

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #37 on: July 03, 2013, 10:24:54 pm »
You guys will like this, finally got what I wanted working, I just need to look at getting the numbers to update and stuff when I click a mousebutton or something and so on.


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

int main()
{

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

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

    int goldamount = 100;

    std::ostringstream gld;
    gld << "Gold:  " << goldamount;




    sf::Text goldtext;
    goldtext.setFont ( arial );
    goldtext.setCharacterSize ( 12 );
    goldtext.setColor ( sf::Color::Yellow );
    goldtext.setPosition ( 50, 50 );

    goldtext.setString ( gld.str () );



    while (window.isOpen())
    {

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

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

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

    }

    return 0;

}

 

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #38 on: July 03, 2013, 10:47:17 pm »
That's pretty much the tutorial about drawing text.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #39 on: July 03, 2013, 10:57:43 pm »
lol yeah exactly, what's interesting is in the end I didn't need to add that much on to get it all working which is nice >_< I used the example in the gamedev thread to help me work it out, now comes the trickier part of making it all interactive. The main thing I ended up having to figure out was that you needed for some reason to add a sstream header in then it all started working fine.
« Last Edit: July 03, 2013, 11:12:22 pm by Lethn »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #40 on: July 03, 2013, 11:47:31 pm »
You had to include the <sstream> header because you were using 'std::ostringstream gld;' which ostringstream is a class presented thru said header.

Again, its great you want to learn SFML but you really need to step back and get general programming knowledge down first.  If you didn't know that you had to include a header to get something from that headers class to work then your programming and/or c++ knowledge is still severely lacking.  Before diving deeper into SFML you may want to at the very least write small programs that revolve around different aspects of programming.  Such programs could be:

Console based:
1.)  Take input from the keyboard, only allow numbers, and then calculate whether that number is prime or not, return true or false, if true return the primes root, if false give a close estimate.
2.)  Simple text file I/O
3.)  Strings, learn to manipulate strings with user input and input from a text file.  Print strings back to the console and print back to another text file.
4.)  A program that takes a text file of random numbers and gives the user an option to pick one of X number of 'sorts' to sort the list.  Sorts could be quicksort, bubble sort, heap sort, any other kind of sort you want.
5.) a simple console based Tic-Tac-Toe game
6.) console based Othello/Chess/Checkers game
7.)  a program that makes use of pointers such as your own Linked List

these are just a few examples of the simple basic things I was taught within my first year of University CS courses.  All of these were done with just the C++ standard library on the console.  If you can get all of these done then you should have the basic understanding of Control structers, control loops, program flow, user/file input and output, pointers, references and values.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #41 on: July 03, 2013, 11:50:16 pm »
what's interesting is in the end I didn't need to add that much on to get it all working which is nice [...] The main thing I ended up having to figure out was that you needed for some reason to add a sstream header in then it all started working fine.
It's nice that you found a solution, but the approach of trying around and putting code snippets from different homepages together won't work in the long term. Especially not with C++.

You have to understand  exactly what you're doing. And if you don't know why you need the <sstream> header, you should definitely read your C++ book more carefully.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #42 on: July 04, 2013, 01:54:43 am »
I'll be looking through the C++ book for sure because it does help, the only problem is reading through a 1000+ page book like that is pretty boring ;_; the explanations are fine, it's just a dull book unfortunately. I find I'm better at learning in bits depending on what I'm doing so I'll get it eventually.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #43 on: July 04, 2013, 11:16:00 am »
Why don't you try the tasks suggested by The Hatchet? Like this, you can apply the knowledge after each step. But for diving directly into SFML, it's probably too early, and you waste too much time understanding stuff and struggling around with compile and runtime errors...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #44 on: July 19, 2013, 10:20:31 pm »
If it seems like I ignored you last time Nexus sorry about that, I've been busy :D I'm actually working on trying to make simple stuff like that now to help me understand the code and it's working well.

I've run into a problem though, while I understand pretty easily now how to deal with strings and getting static text on the screen I'm trying to get the integers to update itself in a way much like you'd find in an RTS or Simulator. I've been reading through the C++ book normally and so I've been looking around the internet and so far the only thing I've found is incrementing and decrementing integers. Either I've misunderstood what they're actually for due to the vocabulary or I'm not using them in the correct way, if you guys could point me to the correct type of code I need to learn or explain things I'd appreciate it.

Here's the code, same as before, but I've done little tweaks and stuff like arranging the words around the statement so I can get used to how it all works and what breaks the code etc.


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

int main()
{

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

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

    int goldamount = 0;
    ++ goldamount;


    std::ostringstream gld;
    gld << "You have " << goldamount << " Gold";



    sf::Text goldtext;
    goldtext.setFont ( arial );
    goldtext.setCharacterSize ( 12 );
    goldtext.setColor ( sf::Color::Yellow );
    goldtext.setPosition ( 20, 20 );

    goldtext.setString ( gld.str () );



    while (window.isOpen())
    {

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

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

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

    }

    return 0;

}

Note: I just double checked and yes I think I have misunderstood but it looks like I need to find some sort of function to add on to make it repeat, some kind of loop perhaps? Time to do investigating :D

Edit: I think it's for loops that I need to go and study, let me know if I'm wrong!
« Last Edit: July 19, 2013, 10:38:29 pm by Lethn »

 

anything