Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 506 507 [508] 509 510 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 824830 times)

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #7605 on: July 26, 2015, 07:23:19 am »

Except that in C#, arrays start at element 0, where it fails. It still fails when I only reference
Code: [Select]
Topic[0].TopicID = "Foo";

Also,
Code: [Select]
Array.Resize<TopicData>(ref Topic, 8);This resizes the array to hold 8 elements.

So does this:
Code: [Select]
Topic = new TopicData[8];
« Last Edit: July 26, 2015, 07:27:42 am by Dutrius »
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7606 on: July 26, 2015, 07:25:06 am »

What I wrote had nothing to do with arrays starting at zero or otherwise. You aren't doing a good job comphehending what I wrote.

0-7 means array size eight, already assuming it starts at zero.

But I had only seen the part where you declared it as size 1 first when I wrote that, which looked like the error.
« Last Edit: July 26, 2015, 07:27:10 am by Reelya »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #7607 on: July 26, 2015, 07:25:48 am »

You aren't initialising any of the elements of the array, so all you have is an array of 8 nulls.

SomeClass[] array = new SomeClass[3];

Is equivalent to doing
SomeClass[] array = new SomeClass[] { null, null, null };
« Last Edit: July 26, 2015, 07:27:51 am by MorleyDev »
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7608 on: July 26, 2015, 07:27:37 am »

yeah, if you have an array of classes, you have to do new on every member, otherwise use structs.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7609 on: July 26, 2015, 07:28:13 am »

^ That would be the error, I forgot how C# is stupid and doesn't have default constructors like c++ does.

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #7610 on: July 26, 2015, 07:29:56 am »

Ahh, thank you. That fixed it.
« Last Edit: July 26, 2015, 07:31:36 am by Dutrius »
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7611 on: July 26, 2015, 07:34:22 am »

^ That would be the error, I forgot how C# is stupid and doesn't have default constructors like c++ does.

So if you do an array of someclass* and don't assign anything to it, you'll be able to read it in C++? news to me.
Logged

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7612 on: July 26, 2015, 07:38:09 am »

^ That would be the error, I forgot how C# is stupid and doesn't have default constructors like c++ does.

So if you do an array of someclass* and don't assign anything to it, you'll be able to read it in C++? news to me.

C++ has functions that are automatically called when creating classes and when classes go out of scope.
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7613 on: July 26, 2015, 07:39:43 am »

Yes, and they are not called when you make a class pointer.

C# classes are the same as pointers to classes in C++, not the same as C++ classes.

C# struct is the same as a C++ class or struct, though.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7614 on: July 26, 2015, 08:35:35 am »

^ That would be the error, I forgot how C# is stupid and doesn't have default constructors like c++ does.

So if you do an array of someclass* and don't assign anything to it, you'll be able to read it in C++? news to me.

In C# arrays are arrays of references - i.e. they're tables of pointers, that must then have actual data created elsewhere. Whereas in C/C++ arrays are a solid block of memory directly containing the objects you asked for. This is more compact, and it's also faster to process than having a lookup table like C# does for arrays. You can make arrays of C/C++ pointers if you want the same functionality as C#. But you're out of luck if you want C# to make the same efficient use of memory as c++.

Just bear in mind that C++ doesn't initialize the allocated memory unless it's told to do so (either by your code or in the definition of the object). This is for efficiency reasons. Say you make an array of ints, then fill that with data in a for loop. If the program had, without your instructions, set the initial array to zeros, then that's extra overhead you didn't need. So, having to be more careful is the price for fast and compact code.

C# is supposed to be more secure because it just has references (which are the secure type of pointers in c++), and not pointers. But in actualilty a c# reference has the functionality of both references and pointers hence it has all the same loopholes as pointers (like crashing your program because it was null). I think combining the two ideas has just made C# programmers complacent rather than improving how pointers work.

« Last Edit: July 26, 2015, 08:48:59 am by Reelya »
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7615 on: July 26, 2015, 10:10:21 am »

C# arrays are not references unless they're of a reference type. A array of ints in C# is exactly the same as an array of ints in C++. Both will be filled with garbage data when you initialize it, but you can still try to read it and not crash.

An array of class instances in C# is pretty much the same as an array of pointers in C++. Both will be null unless assigned.

Yes, C# reference types do have some differences from C++ pointers, but in concept, they're both the same. Both can have null values, both point to the object in question rather than being an object themselves, and both need to be initialized to be used.

As long as you remember that a C# class is analogous to a C++ pointer to a class, rather than being analogous to a  C++ class directly, then things make sense.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7616 on: July 27, 2015, 01:51:35 am »

I'm having some problems now with shaders in Unity. I'm making a terrain mesh, and tried to use vertex colors to define features, but whenever I use a shader that allows the colors, the mesh becomes semi-transparent to parts of the terrain behind it. This is probably due to rendering order of the mesh, e.g. when i look one way, the left half of everything is transparent, but the right half is transparent when I look in the other direction. What I need is a basic shader that recognizes the vertex colors but is also opaque and does z-buffer checking properly.

Monochrome or just texture shaders still work fine, though so there's no actual problem with the mesh, just any color shaders. So anyone play with vertex colors in Unity?

I really want to start defining my own shaders now because I never find the exact one I want in Unity's presets. But ... trying to follow Unity's documentation is useless. They just say "thing exists. It do thing!" without giving even a basic example of how you're meant to use anything. I get most of my actual Unity knowledge from random forum threads.
« Last Edit: July 27, 2015, 01:58:09 am by Reelya »
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7617 on: July 27, 2015, 01:57:03 am »

I have played a LOT with vertex colors, so yeah, I can help.

Mind posting your shader right as it is right now? Then we can see what's wrong with it.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7618 on: July 27, 2015, 02:06:14 am »

I'd also like some screenshots of the situation, please.
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7619 on: July 27, 2015, 02:21:29 am »

I'm having some problems now with shaders in Unity. I'm making a terrain mesh, and tried to use vertex colors to define features, but whenever I use a shader that allows the colors, the mesh becomes semi-transparent to parts of the terrain behind it. This is probably due to rendering order of the mesh, e.g. when i look one way, the left half of everything is transparent, but the right half is transparent when I look in the other direction. What I need is a basic shader that recognizes the vertex colors but is also opaque and does z-buffer checking properly.

Monochrome or just texture shaders still work fine, though so there's no actual problem with the mesh, just any color shaders. So anyone play with vertex colors in Unity?

I really want to start defining my own shaders now because I never find the exact one I want in Unity's presets. But ... trying to follow Unity's documentation is useless. They just say "thing exists. It do thing!" without giving even a basic example of how you're meant to use anything. I get most of my actual Unity knowledge from random forum threads.

Yeah, Unity docs are less than helpful in many regards. A lot of pages have only Javascript examples and not C#, and most don't even have examples. A few EditorGUILayout, GUILayout, OnGUI, etc. methods don't even have descriptions.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.
Pages: 1 ... 506 507 [508] 509 510 ... 795