More of Taters' coding problems.

  • 11 Replies
  • 2669 Views
*

Taters343

  • Official Member
  • 11963
  • Pope/Tater/Robot with flower girl capabilities!
More of Taters' coding problems.
« on: May 14, 2012, 06:37:31 AM »
In C#, I'm creating an array of "Player" objects. Each player has two attributes, and name and a score, which are left blank when the player is created to be set later. The code compiles, but when it tries to set the name or score of a player in the array I get a null reference exception. The code looks something like this, substituting the variables I'm using with constants for the sake of simplification:

Code: [Select]
Player[] playerArray = new Player[5];
playerArray[0].Name = "hello";

I tried creating a Player object that wasn't in an array and it worked fine, but for some reason it won't work in the array. Am I just missing a step or something? I feel like it should be an easy fix and that I'm just missing something obvious.

Never mind, I figured it out. I tried deleting the thread, but it won't let me.
« Last Edit: May 14, 2012, 06:39:23 AM by Taters343 »

*

Lorddave

  • 18127
Re: More of Taters' coding problems.
« Reply #1 on: May 14, 2012, 06:52:26 AM »
What was your problem?
You have been ignored for common interest of mankind.

I am a terrible person and I am a typical Blowhard Liberal for being wrong about Bom.

*

Taters343

  • Official Member
  • 11963
  • Pope/Tater/Robot with flower girl capabilities!
Re: More of Taters' coding problems.
« Reply #2 on: May 14, 2012, 07:44:33 AM »
I didn't declare each individual Player in the Player array, I guess? I didn't think I had to, but when I changed it to

Code: [Select]
Player[] playerArray = new Player[5];
playerArray[0] = new Player();
playerArray[0].Name = "hello";


it worked.

?

sirTheMore

  • 203
  • Hello kind gentlemen.
Re: More of Taters' coding problems.
« Reply #3 on: May 14, 2012, 04:21:19 PM »

Dearest of sirs,
I do rather enjoy the language commonly known as C#.  It would seem to this gentleman that it is a delightful blend of the C and Java languages.  What other languages is thy gentleman fluent in?
Ragards,
sirTheMore


Kind gentlemen, I do wish to declare that although these fora are for the sole purpose of education of the flat earth, I would also enjoy expressing my gratitude for the opportunity to post in them.  Thank you all for your time and interest in this subject.

*

Parsifal

  • Official Member
  • 36118
  • Bendy Light specialist
Re: More of Taters' coding problems.
« Reply #4 on: May 15, 2012, 05:05:51 AM »

Dearest of sirs,
I do rather enjoy the language commonly known as C#.  It would seem to this gentleman that it is a delightful blend of the C and Java languages.  What other languages is thy gentleman fluent in?
Ragards,
sirTheMore



I call it a bastardisation of a perfectly good language (C). But each to his own.
I'm going to side with the white supremacists.

?

Around And About

  • 2615
  • Circular Logic Falls Flat
Re: More of Taters' coding problems.
« Reply #5 on: May 15, 2012, 06:22:10 AM »
Parsifal, if I wanted to learn me some C, are there any resources you would recommend?
I'm not black nor a thug, I'm more like god who will bring 7 plagues of flat earth upon your ass.

*

Parsifal

  • Official Member
  • 36118
  • Bendy Light specialist
Re: More of Taters' coding problems.
« Reply #6 on: May 16, 2012, 12:50:01 AM »
Parsifal, if I wanted to learn me some C, are there any resources you would recommend?

Source code. Seriously, there's no tutor like taking a program you use and trying to add a feature or fix a bug.
I'm going to side with the white supremacists.

?

Thork

Re: More of Taters' coding problems.
« Reply #7 on: May 16, 2012, 01:51:13 AM »
Parsifal, if I wanted to learn me some C, are there any resources you would recommend?

This guys is always helpful. Talks to you like you are an idiot. I need that.
https://www.youtube.com/playlist?list=PL78280D6BE6F05D34&feature=plcp

?

Around And About

  • 2615
  • Circular Logic Falls Flat
Re: More of Taters' coding problems.
« Reply #8 on: May 16, 2012, 04:57:51 AM »
Alright, thanks guys. I will start with some of Thork's videos and see if I can't poke around and work my way up to editing source code. My background is in Pascal, but it was years ago and never got very sophisticated, so I would be most comfortable starting from scratch and revisiting the basics.
I'm not black nor a thug, I'm more like god who will bring 7 plagues of flat earth upon your ass.

?

sirTheMore

  • 203
  • Hello kind gentlemen.
Re: More of Taters' coding problems.
« Reply #9 on: May 16, 2012, 09:17:29 AM »
Parsifal, if I wanted to learn me some C, are there any resources you would recommend?

Source code. Seriously, there's no tutor like taking a program you use and trying to add a feature or fix a bug.

False.  Kernighan and Ritchie's The C Programming Language is considered by many to be the authoritative C programming resource.  There's no tutor like the original designer/implementer of the language, who happens to be one of the authors of the text.
Warmest,
sirTheMore


Kind gentlemen, I do wish to declare that although these fora are for the sole purpose of education of the flat earth, I would also enjoy expressing my gratitude for the opportunity to post in them.  Thank you all for your time and interest in this subject.

*

Parsifal

  • Official Member
  • 36118
  • Bendy Light specialist
Re: More of Taters' coding problems.
« Reply #10 on: May 16, 2012, 01:13:54 PM »

False.  Kernighan and Ritchie's The C Programming Language is considered by many to be the authoritative C programming resource.  There's no tutor like the original designer/implementer of the language, who happens to be one of the authors of the text.
Warmest,
sirTheMore



While that may be a very good resource, it can't possibly teach you C as well as actually using C. A book can give you technical background, but can't teach you how to actually use the language.

Also, argumentum ad verecundiam.
I'm going to side with the white supremacists.

?

sirTheMore

  • 203
  • Hello kind gentlemen.
Re: More of Taters' coding problems.
« Reply #11 on: May 16, 2012, 03:26:35 PM »
While that may be a very good resource, it can't possibly teach you C as well as actually using C.

If you actually read the book you'd know that the book teaches C through using C.

A book can give you technical background, but can't teach you how to actually use the language.

Evidence?

Also, argumentum ad verecundiam.

Irrelevant.

Best!
sirTheMore
Kind gentlemen, I do wish to declare that although these fora are for the sole purpose of education of the flat earth, I would also enjoy expressing my gratitude for the opportunity to post in them.  Thank you all for your time and interest in this subject.