New Gyromite

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: New Gyromite

Post by M_D_K »

yes it will be 44 when the function ends.

Code: Select all

JSL::JSL()
{
        bran_flakes = 44; //its 44 I'm pretty sure
};
[...]

printf("OMG I have %f bran flakes\n", jsl->bran_flakes);
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: New Gyromite

Post by Arce »

Jsl, how are you deducing that it doesn't work? Your example is done right, and it does work how you want...

Maybe it a problem elsewhere? Calling the wrong constructor or something...? Mind posting a code snippet and the output? I'm still not exactly sure what problem you have...

Also, if you find that you're using a bunch of statics, consider a singleton?

Hopefully this'll help some..

Code: Select all

class dildo {
     int member_A;         //Member data (private)
     string asswranger;    //Member data (private)
     public:
           dildo():member_A(44),asswrangler("twat") {std::cout << "def constr call";}
           ~dildo();

          
              //at the end of this func, x and y are out of scope, and asswrangler is "twathole"
              void func_A() {
                    int x,y;
                    x=y=0;
                    asswranger+="hole";
               }
              //at the end, x is out of scope and member_A=whatever the fuck you passed
              void func_B(int x) {
                     member_A=x;
               }
};
printf("OMG I have %f bran flakes\n", jsl->bran_flakes);
Also, bran_flakes is not a pointer, so you would use the dot operator (.) rather than the indirection operator (->)
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: New Gyromite

Post by M_D_K »

Arce wrote:
printf("OMG I have %f bran flakes\n", jsl->bran_flakes);
Also, bran_flakes is not a pointer, so you would use the dot operator (.) rather than the indirection operator (->)
but jsl is...well at least in my version :)

Code: Select all

JSL *jsl = new JSL();
printf("OMG I have %f bran flakes\n", jsl->bran_flakes);
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Re: New Gyromite

Post by JS Lemming »

Code: Select all

class dildo {
     int member_A;         //Member data (private)
     public:
           dildo():member_A(44)
          {
                    std::cout << "member_A is " << member_A;
                    hey();
          }
           ~dildo();

          void hey() { member_A = 55; }

          void corn() { std::cout << "WTF is member_A? " << member_A; }
};
Calling corn() after creating an instance of dildo prints out that member_A is ZERO. That is my problem. I wish it were 55. It's only 55 if I make member_A static.

I don't think a singleton has anything to do with this but I could be wrong.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: New Gyromite

Post by M_D_K »

well that code works for me. So I don't know WTF is going on there.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: New Gyromite

Post by Falco Girgis »

Something must be seriously screwed up. That defies the laws of C++ and OO programming.
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: New Gyromite

Post by Arce »

That should work, so the problem obviously isn't in the actual class.

How're you creating an instance? Are you doing more crap with lists? Is it being screwed when you push and pop them?

Could you show us where you're creating an instance and where you're retrieving the value of member_A? Something sounds seriously fucked.

Also, why are you putting member_A in the initializer list if you're just setting it in the function body? The redundancy shouldn't be a problem, though...

Again, lessee how you initialize an object...If it's not calling your constructor, then maybe member_A is a random value, and your compiler shows 0 for Null? Eh, that's stretching...o.o;;;;
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Re: New Gyromite

Post by JS Lemming »

Holy fucking shit. I am theeeeee dumbest dumb shit alive. Wow. Woooooow.

Ok guys... Wow. Sooo it turns out I deleted the instance of the class right after I made the instance (for debugging purposes a few days ago) and had forgotten to remove the delete... And the fact that it still fucking worked (aside from this member variable abomination) when I called on functions in the no longer existing instance is why I didn't catch the delete till just now. Once again... Wow.

Lesson learned: If you delete your class instance C++ fucks your mother but doesn't tell you.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: New Gyromite

Post by Arce »

Lesson learned: If you delete your class instance C++ fucks your mother but doesn't tell you.
:lol: :lol: :lol:
I rofled!
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: New Gyromite

Post by Arce »

Also, I like your neat little way of saving/loading shit. Looks pretty tight to see an ascii level. ;p
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: New Gyromite

Post by dandymcgee »

Don't worry.. It's always something stupid. Congrats on finding it though!
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Re: New Gyromite

Post by JS Lemming »

Thanks guys.
Arce wrote:Also, I like your neat little way of saving/loading shit. Looks pretty tight to see an ascii level. ;p
Haha yeah. Interpreting the ascii data is pretty ridiculous. Check out what it has to do when it sees a blue pipe "B"...

Code: Select all

	case 'B':
	mapt[x][y] = 0;
	xv=0; yv=0;
	if(mapt[x+1][y] == 'b') {
		xv=1; yv=0;
	} else if(mapt[x][y+1] == 'b') {
		xv=0; yv=1;
	} else if(mapt[x-1][y] == 'b') {
		xv=-1; yv=0;
	} else if(mapt[x][y-1] == 'b') {
		xv=0; yv=-1;
	}
	if(xv!=0)
	{
		for(i=1; ; i++)
		{
			map[x+((i-1)*xv)-1][y-1][1] = '.';
			if(mapt[x+(i*xv)][y] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, HORZ, x-1, y-1, x+((i-1)*xv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '+';
	}
	if(yv!=0)
	{
		for(i=1; ; i++)
		{
			map[x-1][y+((i-1)*yv)-1][1] = '.';
			if(mapt[x][y+(i*yv)] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, VERT, x-1, y-1, y+((i-1)*yv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '-';
	}
	break;
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: New Gyromite

Post by M_D_K »

JS Lemming wrote:Thanks guys.
Arce wrote:Also, I like your neat little way of saving/loading shit. Looks pretty tight to see an ascii level. ;p
Haha yeah. Interpreting the ascii data is pretty ridiculous. Check out what it has to do when it sees a blue pipe "B"...

Code: Select all

	case 'B':
	mapt[x][y] = 0;
	xv=0; yv=0;
	if(mapt[x+1][y] == 'b') {
		xv=1; yv=0;
	} else if(mapt[x][y+1] == 'b') {
		xv=0; yv=1;
	} else if(mapt[x-1][y] == 'b') {
		xv=-1; yv=0;
	} else if(mapt[x][y-1] == 'b') {
		xv=0; yv=-1;
	}
	if(xv!=0)
	{
		for(i=1; ; i++)
		{
			map[x+((i-1)*xv)-1][y-1][1] = '.';
			if(mapt[x+(i*xv)][y] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, HORZ, x-1, y-1, x+((i-1)*xv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '+';
	}
	if(yv!=0)
	{
		for(i=1; ; i++)
		{
			map[x-1][y+((i-1)*yv)-1][1] = '.';
			if(mapt[x][y+(i*yv)] != 'b')
			{
				stageObjects.push_back(new pipe(BLUE, VERT, x-1, y-1, y+((i-1)*yv)-1));
				break;
			}
		}
		map[x-1][y-1][1] = '-';
	}
	break;
Wow!! I bet if I read that I would understand all of it :)
JS Lemming wrote:Holy fucking shit. I am theeeeee dumbest dumb shit alive. Wow. Woooooow.

Ok guys... Wow. Sooo it turns out I deleted the instance of the class right after I made the instance (for debugging purposes a few days ago) and had forgotten to remove the delete... And the fact that it still fucking worked (aside from this member variable abomination) when I called on functions in the no longer existing instance is why I didn't catch the delete till just now. Once again... Wow.

Lesson learned: If you delete your class instance C++ fucks your mother but doesn't tell you.
:lol:

And using accessors in place of direct access to variables doesn't help :)
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: New Gyromite

Post by dandymcgee »

Your variable names make my head hurt. :shock:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: New Gyromite

Post by eatcomics »

dandymcgee wrote:Your variable names make my head hurt. :shock:
That's were they lost me too... :shock:
Image
Post Reply