Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 22 23 [24] 25 26 ... 81

Author Topic: Cloud Scream > Development on Pause  (Read 86903 times)

Boksi

  • Bay Watcher
  • Everyone's dumb in their own special way
    • View Profile
Re: WorldJem Renamed: Cloudscream
« Reply #345 on: November 13, 2009, 07:27:01 pm »

Because it's up in the clouds and you're going to scream a lot?
Logged
[BODY_DETAIL:NAIL:NAIL:NAIL]
[HAMMER:HAMMER:HAMMER]

[TSU_NOUN:nose]
[SUN_TSU_NOUN:art:war]

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #346 on: November 13, 2009, 07:29:24 pm »

The HFS will be in the sky, and will have a large impact on the game.
I thought the name fit pretty well.

Apparently, Alfie has figured something out, which means this thing is moving along again.
I'm in the process of converting the whole thing into a class-based version of itself,
so a lot is being done, but with very few outward differences.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #347 on: November 14, 2009, 10:39:32 am »

Okay, since I have no grasp of how London time works,
I'm going to ask my fellow creatives for help.

How do I access a public variable from another class?

The only way I know how is classinstance.variablename;,
but that only works when an instance has already been declared.

Any help will be appreciated.

Also, how long from now will it become 6 in London?
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Re: WorldJem Renamed: Cloudscream
« Reply #348 on: November 14, 2009, 10:55:01 am »

Theoretically, there's no reason as to why you would do that.  You need to make your variables private (or protected in case you use inheritance) and make public methods that will manipulate those variables.  So, eventually, you need to know nothing about the definition of the function, just the declaration.
If you use correct OPP you can change the structure of your class and the code will still work.  If you use public variables you'll need to change it everywhere.

I suggest you read this:
http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/
http://www.learncpp.com/cpp-tutorial/83-public-vs-private-access-specifiers/
and the following OOP articles wouldn't hurt either... :P
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: WorldJem Renamed: Cloudscream
« Reply #349 on: November 14, 2009, 10:56:53 am »

The current time in London

Hmm... I may have to read the OOP articles too... I know how private and public work, but I'm sure I could be more efficient with my classes and such...
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #350 on: November 14, 2009, 11:05:38 am »

Thanks guys, you are very helpful.

EDIT:

So if I have an instance of lets say THIEF, it would never need to know the contents of HOUSE?
Shouldn't HOUSE's variables be public, so people moving around inside of it can interact with it?
How do I allow a member of class THIEF to get information about class HOUSE?

Also, this is all hypothetical. I am not making a burglary game presently.
(Though I have made one in the past) : )
« Last Edit: November 14, 2009, 11:14:17 am by Outcast Orange »
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Ironhand

  • Bay Watcher
  • the llama is laughing
    • View Profile
Re: WorldJem Renamed: Cloudscream
« Reply #351 on: November 14, 2009, 11:28:28 am »

If your variables are private, you can write public accessor methods for those variables.
Then rather than directly modifying house.loot, you call house.setLoot(), or whatever.
Logged

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Re: WorldJem Renamed: Cloudscream
« Reply #352 on: November 14, 2009, 11:33:13 am »

So if I have an instance of lets say THIEF, it would never need to know the contents of HOUSE?
Shouldn't HOUSE's variables be public, so people moving around inside of it can interact with it?
How do I allow a member of class THIEF to get information about class HOUSE?
You wouldn't need to know the body of the functions (The definition) but you'd know the name, return type and parameters of the functions so you can use them.  Like you do with every other class:
iostream, string, math, etc... those are all classes... you don't access their variables directly but the methods that access those variables.

Code: [Select]
//in the header
class House
{
private:
int nRooms;
bool bTaken;
std::string szAddress;
public:
//Get
//this are declarations
int GetRooms(); 
//...
//Set
void SetRoom(int ro);
//Other functions
void AddRooms(int amount);
//Constructors
House();  //default
House(int ro, bool tak, std::string ad);
//Destructor
~House();
};
//end of header...

This is all you need to know... the declarations and a good documentation telling what does each of them do.

Then comes the .cpp.
Code: [Select]
#include "nameofheader.h"

//defintions per se
int House::GetRooms() {return nRooms;}
//etc.
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #353 on: November 14, 2009, 11:55:36 am »

I think what I was trying to do was pointless.
The code I was trying to stuff into a class didn't really belong there.
Basically, my game flow has a large function called inputloop.
This is an endlessly looping list of possible actions based on input and circumstance.
I was trying to stuff it into a class, but it probably just belongs as its own function in its own cpp.

Sorry about that.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #354 on: November 14, 2009, 12:06:12 pm »

The more I play around with this, the more I think inputloop should be a class.
It has all of these extra (should be private) variables to keep track of itself.
bool inputgo; is a good example.
This tests if an action is allowed to be taken or not.
Any input?
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: WorldJem Renamed: Cloudscream
« Reply #355 on: November 14, 2009, 12:11:31 pm »

Quote
All that stuff about public vars vs. private with accessors

Do you know WHY you should? If you know WHY, you can infer WHEN, because nothing is universally best.

Yes, if you think that you may one day want to change it so that

int House::GetRooms() {return nRooms;}

is

int House::GetRooms() {return nRooms-nSecretRooms+nKnownSecretRooms();}

it would be better. However, sometimes it's better to directly use the variable.


It seems that most standards(such as avoid GOTO) are in place to ensure that the code can be altered or expanded without breaking anything.

Quote
So if I have an instance of lets say THIEF, it would never need to know the contents of HOUSE?
Shouldn't HOUSE's variables be public, so people moving around inside of it can interact with it?
How do I allow a member of class THIEF to get information about class HOUSE?

Making the contents public is fine as long as you don't mind limiting future expansion. Making it private with accessors is fine as long as you don't mind a potential slight speed loss(if the compiler doesn't just realize that both ways do the same thing, and optimize it for you), and scattering the logic of the code a bit more(though with decent naming, this shouldn't be a problem).


Go with what you feel is best, because some/many/all standards are there to make things easier in the long run, not simpler in the short run, and since you are learning a new subject, you want easier above all, at least until you understand why the standards exist.

-new post-

State variables? Are they just used in a single function?

If so, you may optionally make them static variables within the function, though it probably isn't good OOP, since if you ever were to break it up, you would have to promote them the class vars or global-to-the-file vars.
Logged
Eh?
Eh!

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #356 on: November 14, 2009, 12:22:13 pm »

I found a way for input to work fine without variables, but I have a new problem.
Here are the basics:

These are two lines in my main, before the loop:
Code: [Select]
int samus;
#include "inputloop.cpp"

These are the first two lines of my input loop:
Code: [Select]
void inputloop(){
    samus = 1;

Why am I getting the "samus was not declared in this scope" error?
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream

Alexhans

  • Bay Watcher
  • This is toodamn shortto write something meaningful
    • View Profile
    • Osteopatia y Neurotonia
Re: WorldJem Renamed: Cloudscream
« Reply #357 on: November 14, 2009, 01:57:57 pm »

First, The main needs to include the "header.h" file... not the .cpp

-class.h will declare the class
-class.cpp will define the functions of the class (and include the class), you'll need to use the scope operators.
-main will include the class.h

To use the scope operator...

IT's "::".

Code: [Select]
ClassName::ClassFunction(<parameters>)
{
  /*Now you can use the implicit this-> pointer to access the elements of your class*/
return this->nRooms;
return nRooms;  /*this is the same but with the implicit pointer to the current object*/

}

I've just come back from running some errands (Buying stuff for a friend's party :)) And I have other things to do outside but I'll have more time tomorrow to answer any doubts (or maybe today between (19-20hs GMT -3)...

See ya.

EDIT:  Btw, static variables can be useful within a class for certain things... For example, keeping track of the number of instances you create... Those static variables will need to be modified through static functions.  A static function and variable have the characteristic of belonging to all the instances of a particular class at the same time.

qwerty:  Don't worry so much about performance at this point.  Performance won't suffer for just using classes.  At this level it depends much more on how he structures the program and the efficiency of his algorithms.
« Last Edit: November 14, 2009, 02:03:09 pm by Alexhans »
Logged
“Eight years was awesome and I was famous and I was powerful" - George W. Bush.

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: WorldJem Renamed: Cloudscream
« Reply #358 on: November 14, 2009, 02:37:00 pm »

#include files literally puts the code of one file into another.
Logged
Eh?
Eh!

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: WorldJem Renamed: Cloudscream
« Reply #359 on: November 14, 2009, 08:53:29 pm »

Okay. This has gotten much further along today.
I now have a tile class, and some basic functions.
I'll be figuring out how to get my universe creation in tomorrow hopefully.
I can't wait for this whole thing to be in classes,
the changes me and Alfie worked out will save tons of time on the programming side later.
It's a great investment, considering the game probably won't be able to move on without it.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream
Pages: 1 ... 22 23 [24] 25 26 ... 81