New to Unity, not new to software engineering. I’m looking to log an array (without bloating the code), and this is turning out to be a challenging and complicated task.
In other languages, it would be trivially easy. For example, in js you’d simply convert the array into a JSON.
I see there are C# packages that let you do similarly, but for all I know there might be a simple and elegant solution that I do not know about.
Since you have already necroed this thread , have you actually read my post which was the last one? Of course JSON (javascript object notation) is available in javascript. For most other languages there usually are packages or built-in json frameworks. However unlike javascript most languages which are more sophisticated and closer to the hardware have much more datatypes than javascript. So usually only a subset can be serialized. So just logging an “array” doesn’t mean much as not every possible type can be serialized.
In C# every type has a ToString method. However most complex types (classes or structs) have to explicitly implement / override this method or it will just return the type name. In my examples I specifically used ToString on the array members.
It sounds like perhaps you would be happier if you went and coded in those languages.
Are you struggling to convert data? Is that what’s happening here?? Because that’s actually what it looks like.
Rather than colorizing everything with “it would be trivial” and “without bloating the code” and other meaningless observations and conditions, try this structure to report problems to complete strangers in an international engineering forum:
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
what you want
what you tried
what you expected to happen
what actually happened, log output, variable values, and especially any errors you see - links to documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?
My apologies for not providing code snippets and clarifying what I meant by “bloated”. By bloated, I simply mean writing loops and logging in each iteration.
Also, not sure how to interpret all of this other than that its clear that you two are angry at me for saying negative things about C# and Unity both here and in the other thread we were arguing on.
Code snippet:
Javascript, if logging to a backend or IDE console: console.log(JSON.stringify(myArray))
Or, if logging to the Chrome console: console.log(myArray)
C#: Debug.Log(???); // something approximately as simple and fast to type