Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 20 Apr 2010
Offline Last Active Today, 10:53 AM

#5198316 C++ Number guessing

Posted by LennyLen on 15 December 2014 - 08:18 AM

What do you suggest to use to replace system("cls")?


There is no universal way of doing this.   There's no way of guaranteeing that stdout is even going to the screen, so clearing the output when it could be going to a printer or a file makes little sense.  For a simple number guessing game, I'd just leave the console as it is and not worry about clearing it. There are libraries such as ncurses/pdcurses that are designed to allow console output, but I haven't used either one for a long time so I have no idea how portable they are these days.

#5198307 C++ Number guessing

Posted by LennyLen on 15 December 2014 - 07:36 AM

That's definitely better.  Now try doing it without using any global variables at all.


Also, be aware that using system("cls"); is not portable.  It will work on DOS/Windows, but is unlikely to work on any other operating system.

#5198093 C++ Number guessing

Posted by LennyLen on 14 December 2014 - 03:41 AM

Use the prefix std:: to indicate the namespace.
std::cin, std::cout and std::endl, instead of cin, cout and endl.


In addition to this, if there is a particular function/variable from within a namespace that you use a lot you can also do this:

#include <stdio>

int main() {
   using std::cout;
   using std::endl;
   cout << "Hello World!" << endl;

   return 0;

#5195454 accuracy bars - quick question

Posted by LennyLen on 30 November 2014 - 02:24 AM

However, I can foresee a few issues with this in terms of player skill progression, possibly slowing things down, balancing problems, maximum reaction speed....etc etc. Obviously, I don't know how impactful (or not) this might be, so was hunting for some discussions that might have already been had online.


To me a dungeon crawler is more of a tactical game than an action game, and it's one of the reasons I play them (along with other types of strategy/tactical games).  If I was playing such a game and I discovered it had skill testing mechanisms, I would just stop playing immediately.  This is because I have terrible reaction times and timing, and am extremely uncoordinated.  I do not get better with practice and only get frustrated when games require me to do certain things at certain times.

#5195090 Health bar graphics instead of text

Posted by LennyLen on 27 November 2014 - 08:12 PM

You're going to have to be alot more specific if you want somebody to show you in code, since we don know what graphics library or language you are using.


The simplest way is to first draw a background rectangle of a certain width (we'll call the width w).  Then on top of that you can draw another rectangle in a different colour.  The width of this rectangle will be w * total_life / current_life.

#5194315 My Pokemon Game

Posted by LennyLen on 23 November 2014 - 02:42 PM

I hope you realize that despite the fact that you state on your site that the Pokemon IP belongs to Nintendo, and that you also say you don't intend to infringe on it, you still are infringing on it, and they will very likely get your site taken down if it ever gets big enough to get their intention.


Save yourself the hassle and come up with your own idea instead of taking someone else's.

#5193976 Proper C++ header file?

Posted by LennyLen on 21 November 2014 - 09:19 AM

Okay.. that means following standards their teachers set them. What I'm writing is an application of good programming standards, not commonly followed standards. I certainly wouldn't recommend everyone go around throwing macros in everything just because a student comes in here with their teacher having asked for some giant macro horror page for their next assignment.

Just to clarify, I wasn't refering to the arbitrary stylistic standards that some institutions expects students to adhere to, but actual official standards (ie ISO).



I certainly appreciate the point you're trying to make, but I'm also trying to make one that we shouldn't just go "Okay, everyone do it the old fashioned way."


What I'm hoping people will be able to take away from this, is that there are two ways this can be done - one which should always be good enough and which most compilers will support, and one which is the official sanctioned method which is universally supported (at least by standards compliant compilers).  Which should be used is up to the individuals needs.

#5193961 Proper C++ header file?

Posted by LennyLen on 21 November 2014 - 07:45 AM

Frankly I don't see a reason not to use it unless someone specifically asks you not to, like at a job or something. Wasted opportunity to give more information to the preprocessor.


The reason I brought it up was because we're in the "For Beginners" section, where we try to be as exact and correct as possible.  There are also a lot of students reading this section, and students are often instructed to follow standards.  For them, using non-standard pragmas could cost marks.

#5193886 Proper C++ header file?

Posted by LennyLen on 20 November 2014 - 05:44 PM

I would also suggest to replace







#pragma once


it's simpler and you don't need the #endif at the end smile.png


The only problem with it is that it is not part of the C/C++ standard, so while it is supported by major compilers, it can't be guaranteed to always work.

#5191071 Game development by a beginner

Posted by LennyLen on 04 November 2014 - 03:47 AM

You need to know basic Object Oriented Programming principles and no you don't need to be old. 


This is completely false.  While OOP can be used quite effectively for game programming, it is definitely NOT a requirement.

#5181539 newbie in game development

Posted by LennyLen on 19 September 2014 - 08:08 AM

Downvoting somebody for simply asking a question is not a good move.  Especially when it's there first post here.  Yes, it does get frustrating seeing the same questions asked over and over, but that's no reason to make somebody feel like they've done something wrong just for asking a question (that is why this forum is here after all) .


Of course, if they keep asking the same question, that's a different matter, but such was not the case here.

#5179649 Did I begin learning late?

Posted by LennyLen on 11 September 2014 - 12:38 PM

Or, people could be down-voting just because they can. It happens quite often on the internet, especially on youtube.


In this case, I don't think so.  I looked through the history of the person that did the down-voting, and there is no past pattern of this behaviour, which you would expect from a serial down-voter.

#5179568 Did I begin learning late?

Posted by LennyLen on 11 September 2014 - 06:57 AM

why down votes ?!


I can't answer for the person who did it, but my guess would be because you started repeating yourself without saying anything new.

#5177609 Did I begin learning late?

Posted by LennyLen on 02 September 2014 - 01:46 AM

I learned more about computer science in 2 years of university than I ever did during my years in middle school (see how I just dropped that age reference in there? I promise not to be a jerk about it).


Agreed.  I started very, very young.  I didn't have anyone to teach me though and for years the only language I had access to was BASIC, so when I finally did start to learn how to program properly, I had a lot of bad habits to unlearn.

#5176687 How deep can you nest functions in c++

Posted by LennyLen on 28 August 2014 - 09:16 AM

Nesting is what aregee did, blocks inside blocks (like chained "if" statements). Calling functions from another functions (what the OP did) is not nesting and it's not limited by the bracket depth, otherwise you'll be limited in your app by the call hierarchy of any external library you're using, or using recursive functions won't work well.

It's also worth noting that nesting within a function is not the same thing as a nested function.  Neither standard C or C++ allow nested functions (though gcc does have an extension to allow nested functions).
edit: I should give an example.
This is nesting within a function:

int foo() {
  int x = 5;
 return x;

This is a nested function:

int foo() {
  int bar() {
    int x = 5;
    return x;
  return bar();