C# Noob Question

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
TroyMac1ure





Posts: 29
Joined: Sun Feb 10, 2008 10:39 am

C# Noob Question

Post by TroyMac1ure »

I'm no noob at programming, but Windows is new to me. I'm trying to fix some bugs in a program & I have the following lines:

Code: Select all

MetaSplitter.SplitIdent id = (MetaSplitter.SplitIdent) i;
id.offset += reflex.translation + (reflex.chunksize * x);
Now "id" is set to "i", but when "id.offset" gets changed, so does "i.offset"
How can I seperate the two so that "i" isn't affected by changes to "id"?

Thanks,
Troy
User avatar
JacksonCougAr




Recreator

Posts: 2333
Joined: Fri Jan 12, 2007 1:56 pm
Location: Canada
Contact:

Re: C# Noob Question

Post by JacksonCougAr »

Create a new object for it, your just referencing the same object here.
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Re: C# Noob Question

Post by OwnZ joO »

Jackson is correct.
Make a new MetaSplitter.SplitIdent object.
I don't know all the properties of split ident, but you should do it something like this.

Code: Select all

MetaSplitter.SplitIdent temp = (MetaSplitter.SplitIdent)i;
MetaSplitter.SplitIdent id = new MetaSplitter.SplitIdent();
id.offset = temp.offset + (reflex.chunksize * x);
.
.   // fill in other properties of SplitIdent
.
User avatar
TroyMac1ure





Posts: 29
Joined: Sun Feb 10, 2008 10:39 am

Re: C# Noob Question

Post by TroyMac1ure »

Saying it has 10 variables contained in it, I would therefore have to go through and set each variable manually, correct?

i thought this may be the cae, so I created a new constructor that would take a metaSplitter object and the constructor would transfer each variable to the newly created metsplitter object.

Is this considered the proper way of doing it? I know how hard it is to break bad habits, so I want to learn the correct mathod from the start.

thanks
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Re: C# Noob Question

Post by OwnZ joO »

A SplitIdent constructor that takes a split ident? I would say that's a good enough way to do it. Also, any of the properties that are reference types(classes) you would need to do the same thing for, or else you will have the new one and old one pointing to the same stuff.

The only other way I could see doing it would be to have a private constructor that takes a SplitIdent, and have a public method Duplicate that calls the private constructor, but that's not in any way necessary, especially in entity.
Post Reply