Planet[] planetArray = new Planet[5];planetArray[0] = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue);
4/16/2008 9:27:19 AM
putting this in chit chat, for one
4/16/2008 9:31:37 AM
^
4/16/2008 9:31:50 AM
I put it in tech talk and nobody responded.
4/16/2008 9:34:15 AM
all they do in this section is post gifs of dancing fruit.
4/16/2008 9:35:17 AM
Plus it's in chit chat so people can rickroll it and post tittyballs and whistle for a cab and when it came near.But hopefully one person will be nice enough to help me with my noobishness.
4/16/2008 9:35:24 AM
4/16/2008 9:36:28 AM
i dunno man, it compiles ok for me[Edited on April 16, 2008 at 9:40 AM. Reason : prolly a syntax error in a surrounding line. forgot a ) or something]
4/16/2008 9:39:48 AM
That's what I was thinking but in the other thread he said that these work. So I'm assuming he was just replacing the code above.
4/16/2008 9:43:48 AM
Yeah...basically, the constructors not using the array work fine. If I insert the one with the arrayplanetArray[0] = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue);that line, specifically, is the one which has the errors.
4/16/2008 9:48:34 AM
THESE PRETZELS ARE MAKING ME THIRSTY
4/16/2008 10:06:43 AM
like i said, it compiles just fine for me. post the entire code or something.
4/16/2008 10:07:50 AM
THIS SHALL BE PRECEDENTIF THE MODS CAN CREATE DUPLICATE THREADSTHEN BY GOLLYSO CAN Ip.s. maybe something like Planet[] planetArray = new Array[5]; will fix it? (i have no idea about C#)
4/16/2008 10:14:47 AM
4/16/2008 10:18:49 AM
4/16/2008 10:28:55 AM
i'm tellin ya, it works fine. you shouldn't need to initialize via loop or any such nonsensery
4/16/2008 10:31:43 AM
Full code:(Disclaimer, as in the other thread--I haven't done any programming in years, and I'm learning C# for funsies all from the built-in documentation; this code is probably ghetto as all hell)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace tehgraphhhixzss{ public partial class planets : Form { private System.Windows.Forms.Timer timer1; public planets() { InitializeComponent(); this.SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); } public class Planet { double mass, radius, x, y, dx, dy = 0; System.Drawing.Brush planetColor; public Planet() { //nothing } public Planet(double m, double r, double xpos, double ypos, double deltax, double deltay, System.Drawing.Brush pColor) { mass = m; radius = r; x = xpos; y = ypos; dx = deltax; dy = deltay; planetColor = pColor; } public void Draw(System.Drawing.Graphics graphicsContext) { System.Drawing.Rectangle planetRect = new System.Drawing.Rectangle( (int)(x - radius), (int)(y - radius), (int)(radius), (int)(radius)); graphicsContext.FillEllipse(planetColor, planetRect); // graphicsContext.DrawEllipse(penColor, planetRect); } public void Update() { x += dx; y += dy; } public double getX() { return x; } public double getY() { return y; } } int timesDrawn = 0; Planet[] planetArray = new Planet[2]; Planet planet1 = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue); Planet planet2 = new Planet(20, 50, 300, 300, 2, 3, System.Drawing.Brushes.BlanchedAlmond); //the following line won't compile //planetArray[1] = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue); protected override void OnPaint(PaintEventArgs e) { planet1.Draw(e.Graphics); planet2.Draw(e.Graphics); timesDrawn++; } private void timer1_Tick(object sender, System.EventArgs e) { planet1.Update(); planet2.Update(); this.Invalidate(); } private void Form1_Load(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { // label1.Text = label1.Text + "!"; } }}
4/16/2008 10:32:51 AM
don't use an array. ever. they are dumbdo this... make an object called Planet (sounds like you have one)then make a List<Planet> myPlanetList and start adding them to the listmyPlanetList.add(_someNewPlanetIjustCreated);
4/16/2008 10:33:59 AM
attention jon morgan, i do indeed believe i know the answer to your question.feel free to PM me.also, are you coding for fun now?
4/16/2008 10:34:23 AM
yes, use Lists instead.move that line to the constructor and it'll work
4/16/2008 10:42:31 AM
yeh thats b/c arrays are declared this way:Array planetarray = new Array[100];change it tooList<Planet> myPlanetList = new List<Planet();Planet p = new Planet(20, 50, 300, 300, 2, 3, System.Drawing.Brushes.BlanchedAlmond);myPlanetList.add(p);get my drift???
4/16/2008 10:42:41 AM
Planet planet1 = new Planet(10, 21, 100, 100, 5, 5, System.Drawing.Brushes.AliceBlue); Planet planet2 = new Planet(20, 50, 300, 300, 2, 3, System.Drawing.Brushes.BlanchedAlmond); List myPlanetList = new List(); myPlanetList.Add(planet1); myPlanetList.Add(planet2);
4/16/2008 10:54:58 AM
reinstall .NET
4/16/2008 10:55:45 AM
List<Planet> myPlanetList = new List<Planet>();copy past that motherfcker ver batim[Edited on April 16, 2008 at 10:57 AM. Reason : .]
4/16/2008 10:56:33 AM
lol. C# hates you
4/16/2008 10:56:49 AM
I can literally copy the following example from MSDN documentation:
List dinosaurs = new List(); Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity); dinosaurs.Add("Tyrannosaurus"); dinosaurs.Add("Amargasaurus"); dinosaurs.Add("Mamenchisaurus"); dinosaurs.Add("Deinonychus"); dinosaurs.Add("Compsognathus");
4/16/2008 10:58:20 AM
lolz. listen to me or qntmfred or you lose.
4/16/2008 11:01:16 AM
you can't do planetArray[0] or planetList.Add() out in the middle of the class, it has to be within a method or constructor.
4/16/2008 11:10:55 AM
^ Gotcha. I think that was the main cause of all my woes.
4/16/2008 11:19:19 AM
haha. I didn't even notice that they were hanging out all alone. oh and qntmfred for tww owner.
4/16/2008 11:21:40 AM
Okay, second (third? fifth??) retarded question:where can I put the list declaration that isn't just in the body of the class where it's accessible by all the relevant methods? IOW, I was just declaring the individual objects in the body of the class and then using them in timer1_Tick() and Update(). Where should they go now?I should have called this thread HOLD MY HAND, BITCHES.
4/16/2008 11:28:48 AM
you would want to declare it outside the methods and constructor then, i do it above the constructors usually.make it public if you want to be able to access it from anywheremake it private if you are only using it in your 1 class there
4/16/2008 11:32:31 AM
you can put those objects out in the middle of the class (declare it). but once you start doing something with it, you gotta put it in a method
public class Example{ private int i = 0; // this is a declaration of the field i. we also optionally initialize the value to 0 Example() { i = 3; // the variable i is within the scope of the constructor, so we can access it here int a = 7; // this variable is only within the scope of the constructor. other methods can't get to it }}
4/16/2008 11:33:06 AM
Thank you very much guys, I now have it running.Rat and qntmfred, I owe you guys a handjob.
4/16/2008 11:41:02 AM
yay!wait, wat?
4/16/2008 11:43:48 AM
just not at the same time
4/16/2008 11:45:29 AM
4/16/2008 11:46:47 AM
^^ see, i was thinking the opposite. either both at once or i'm out
4/16/2008 11:51:43 AM
cscirclejrek
4/16/2008 11:52:58 AM
BEST PROGRAMMING THREAD EVAR!!! That said, boy do I need to look up some C# and C++ syntax crap.You'd think I'd get it with java vut there's a few lines in there I'm like...do wtf?
5/10/2008 10:08:37 PM
such as ?
5/10/2008 11:47:03 PM
what the hell language are you speaking?HiGh ScHoOl ViRgIn?
5/10/2008 11:55:43 PM
i got a C- in Javai r not very good at programming
5/10/2008 11:57:36 PM
I CAN HAS MORE PROBLEMS/message_topic.aspx?topic=526919]
5/20/2008 12:34:56 PM