Results 1 to 4 of 4

Thread: I've hit a wall in .NET

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Location
    CA
    Posts
    2

    I've hit a wall in .NET

    Okay, I'll spare all the details because I'm REALLY not good at explaining them, but let's say I have a string of code, such as...

    objectName.location = (x, y)

    ...but I need to take the name of an object, which is stored in a variable, and execute that same line of code using the name stored in the variable.

    For instance, let's say the name "ObjectOne" was stored in variable "objectName", and I wanted to run the code:

    ObjectOne.location = (x, y)

    However, the name stored in "objectName" could be anything, so simply typing out the above code would not work, I need to somehow execute the same code, but using the variable to do it with whatever the name of that object might be:

    (name stored inside variable "objectName").location = (x, y).

    but typing "objectName.location = (x, y)" does not work. Does anyone know another way to solve this problem?

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: I've hit a wall in .NET

    If you have several game objects, lets say ObjectOne, ObjectTwo and ObjectThree all of type ObjectType then you could use the following code:
    Code:
    ObjectType objectName = ObjectOne;
    objectName.location = (x,y);
    //ObjectOne's location is now (x,y)
    objectName = ObjectThree;
    objectName.location = (x2,y2);
    //ObjectThree's location is now (x2,y2), and ObjectOne's location is still (x,y)
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Location
    CA
    Posts
    2

    Re: I've hit a wall in .NET

    Hmm, I think I see, so by preceding the text "objectName" with the ObjectType, say "PictureBox", the text objectName is recognized as an object, rather than just a variable, in the following lines of code?

    EDIT: I must have misunderstood, that did not work.
    Last edited by Kiyu; May 24th, 2007 at 11:06 AM.

  4. #4
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: I've hit a wall in .NET

    In my example objectName is a variable of type 'ObjectType', which can refer to an object of that type (ObjectType).
    If you wanted to change a picturebox's location (a different picturebox each time) you'd do something like this:

    Code:
    PictureBox objectName = PicBoxOne; //Declare the variable objectName as a variable of type 'PictureBox', with an initial value of PicBoxOne (so objectName now references PicBoxOne)
    objectName.location = (x,y); //Since objectName references PicBoxOne this line effects PicBoxOne
    //PicBoxOne's location is now (x,y)
    objectName = PicBoxThree; //Set the variable objectName to reference PicBoxThree
    objectName.location = (x2,y2); //Since objectName now references PicBoxThree this line effects PicBoxThree
    //PicBoxThree's location is now (x2,y2), and PicBoxOne's location is still (x,y)
    I would give you a complete example, but i only have C# installed.
    Last edited by SLH; May 24th, 2007 at 12:39 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width