Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 199 200 [201] 202 203 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886956 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3000 on: September 29, 2012, 04:22:20 am »

I think that's defining the class.

Initializing it is like this:

int main() {
  ...
  myclass object(argument1, argument2);
  ...
}


Creating a new object. At least, that's how I think it is >.> Not quite sure. If you're meaning the initializing function, if it's simple, go ahead and define it in the class.

class myclass
{
  public:
  myclass(int arg1, int arg2) { var = arg1+arg2;}
  private:
  int var
};


To call a function from a different source, you need to #include that file, then call normally. If a function void function() is in myheader.h, #include "myheader.h" (or wherever your header is) and call function() normally.


NINJA: @kaijyuu : I don't see where there's a global variable there... the myObject after a class is just an example of a class name, I think. Don't quote me, though xD
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3001 on: September 29, 2012, 04:23:07 am »

I'm actually guessing that it's a global variable since I've never seen that syntax before :P But it kinda looks like one!
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3002 on: September 29, 2012, 04:27:48 am »

Global variables!

int globalvariable;
extern int externalvariable;

void function()
{
  int local_variable;
}


Global variables are declared (defined? @_@) outside of functions.
External variables have extern next to them and can be used in other files too.
Local variables are inside functions or classes and are only accessed either inside them or by things like classname.variablename.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3003 on: September 29, 2012, 04:31:53 am »

Kaijyuu is right, it would initialize it as a global scoped object.

and Skyrunner, thats just a different way to initialize an object,

you can do

class myclass
{
public:
private: //blah blah blah not typing it out
}

int main()
{
myclass myobject;
}

^^^that^^^ would make the object myobject local to the scope of main,

while

class myclass
{
     public:
     myclass();

     private:
     int var;
}myObject;


initialized an object named myObject, of class Myclass, but of global scope.



also, skyrunner, it's in bad practice to include a constructor with parameters without including a default parameter.   :P
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3004 on: September 29, 2012, 04:35:59 am »

sorry for the doublepost,  :P (jk, i'm not really that sorry)

See, I love my book thats teaching me c++  (the one that I've been singing the praises of just about every time I post) because it teaches me ALL of the ways of doing things as I learn them, 
and it's been more than once that I've actually taught things to people that have been programming c++ longer than me, just because they never learned you could do it that way.

it's just kind of hazy as to when/why certain methods are better/worse than others.
up until now I've only been working on smaller projects, so it's been no issue to me to make them local,
but I understand now why you'd want to.

and I guess I've been getting object declaration and initialization confused, well not exactly, just a terminology mishap, because there is the class definition, the object declaration, and object initialization, and really the initialization is the constructor, which happens during declaration, so thats why I got mixed up.


also, skyrunner, I'll go into detail as to WHY that's bad practice.  (but I assume you already know this)

if no constructor is listed, it makes a default constructor that declares the member variables, but doesn't initialize them, giving them erroneous values.
BUT, if you declare a param. constructor, but declare the object without params, it won't make a default constructor for you, and you'll get a runtime error, so it's better practice to include a default constructor alongside your param constructor.  (or I guess it's not really necessary if you know what you're doing and only declare objects with a matching param. list)
« Last Edit: September 29, 2012, 04:44:44 am by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3005 on: September 29, 2012, 04:41:52 am »

I still use global variables for a few things. Mostly drivers; if I need something to keep track of, say, all the graphics data, I would have a GraphicsDriver class that does all that. Even those aren't necessary to extern into other .cpp files though, as you can just make some functions to access them in their original .cpp's scope.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3006 on: September 29, 2012, 04:50:31 am »

I think I'm going to make the object that controls the window global,
the one that is in charge of resizing the window, change resolution, making the X in the top right close said window, toggle fullscreen, etc.

that would / should be a good idea,.. right?
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3007 on: September 29, 2012, 04:51:56 am »

Whatever works and that you understand is a good idea. :) You really don't need to worry much about "proper" coding until you're doing group projects, or projects large enough that keeping track of everything becomes a major issue.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3008 on: September 29, 2012, 04:52:39 am »

I already know not providing a default constructor is bad >.> I just didn't think that I needed to provide all the boilerplate for an example.

For me, I use global variables for POD structures, mostly.

Also, double ninja'd xD
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3009 on: September 29, 2012, 05:03:28 am »

-snip-
I figured you did, thats why I said
(but I assume you already know this)


Whatever works and that you understand is a good idea. :)
ok, good, I'm just going to tackle this, throw everything I have at it, then cry when it doesn't work and come to you guys for help in a few days to fix some stupid little thing that I overlooked.
and this is a group project, it's just I'm the only programmer -_-

it's a game that really sounds like it would be better off as a flash or java(smartphone) game, but it's good experience me thinks, and hopefully when done will be a pretty little gem sitting alone in my programming portfolio.
also, it should probably be in OpenGL, but I want to get familiar with all of "this" before I tackle that beast, so this should be my last project done with software rendering, and if it really ends up being super awesome, and/or deserves it, my first hardware accelerated game might just be a port of it..
ooooo that would be cool! because then I could do diagnostics on it to compare CPU usage and stuff like that!
*squeee* exciting!

edit: sorry, I turn into a little girl when I get excited..

double edit: ran into a little hiccup, but nothing I can't fix, but i'm going to sleep and will work on it tomorrow.
just one thing,  when you declare global variables, they're still only in the scope of that one source file, right?  so instead you should make it a class member variable so you can access it from the other source files, right?   I've been programming with just one source file, my structure is kind of messed up, but I get it now, and just need to restructure a good amount of the code i've already written for this project. (I started it off as a single source project, then realized it was time to get organized)
« Last Edit: September 29, 2012, 05:26:10 am by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Mini

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3010 on: September 29, 2012, 09:06:06 am »

just one thing,  when you declare global variables, they're still only in the scope of that one source file, right?  so instead you should make it a class member variable so you can access it from the other source files, right?   I've been programming with just one source file, my structure is kind of messed up, but I get it now, and just need to restructure a good amount of the code i've already written for this project. (I started it off as a single source project, then realized it was time to get organized)
Global variables!

int globalvariable;
extern int externalvariable;

void function()
{
  int local_variable;
}


Global variables are declared (defined? @_@) outside of functions.
External variables have extern next to them and can be used in other files too.
Local variables are inside functions or classes and are only accessed either inside them or by things like classname.variablename.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3011 on: September 29, 2012, 10:15:40 am »

well yeah, OpenGL > DirectX in just about every way.
On the contrary; it was my understanding that DirectX had been pulling out ahead of OpenGL for a little while now. More robust feature set, etc and so fourth. It's just that DirectCompute is too closely tied to it for general purpose GPU programming. Though I can see it being really nice for particle systems or similar graphics-but-not-quite-graphics things. For more general purpose use, OpenCL and CUDA have larger feature sets and are easier to use.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3012 on: September 29, 2012, 10:24:50 am »

Some compilers support #pragma once, which I think does the same thing.

This is true, although #pragma once is not standard, and should not be expected. GCC supports it, but bitches at you during compilation for using it.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3013 on: September 29, 2012, 11:02:58 pm »

Mini, that quote, from Skyrunner, doesn't answer the question I had about global variables,
it's like asking someone,
Person 1: Hey, does this vehicle run on gasoline, or is it electric?
and they reply,
Person 2: that guy over there told me, that when you turn on the engine, and accelerate, the vehicle accelerates. 

yeah... uhh... that's nice, I guess, idk, kind of sounded like person 2 is mentally disabled, he added no new information to the conversation, and just said something that is pretty much common sense.
see Mini,  in this example, you are person 2.
that is how much I appreciated your post.

alway, that's propaganda spread by Windows, DirectX likes to say, soo our new version (say DirectX11) has this crazy new feature! thats brand new and never been used before!
what they don't tell you, is that OpenGL has had it for months or even years now, no they're too busy showing you how great DirectX is.
this is what happened with tessellation as well as many other features.  Plus they use scare tactics to drive programmers away from OpenGL, by claiming windows isn't going to support OpenGL, ( a claim they've made with Windows XP, Vista, and 7) they say they aren't going to support it so programmers shouldn't use it if they want to make games on windows, then when the OS comes out, it turns out that it actually DOES support it, and they were just lying about not supporting it.

and Mego, so I should get used to doing the other method, rather than doing it the #praga once way?
« Last Edit: September 30, 2012, 02:59:07 am by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3014 on: September 29, 2012, 11:04:32 pm »

Does anyone have a Python tutorial that they recommend? My newest part-time project uses it :P
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread
Pages: 1 ... 199 200 [201] 202 203 ... 796