I’m sure my creative thread title lured you into my question! I have just recently gotten to a point where I need to know what shorts, doubles, and structs are. I kind of have an idea of what doubles are, but I have never used shorts and structs.
Here’s what I think I know:
Structs are kinds like functions or classes right?
Doubles are bigger floats? I don’t really get how you can have a bigger float
Shorts…I don’t know anything about
Some easy explanations that don’t use complex coding terms would be awesome. Explain it to me like I’m 8.
structs are like classes, but their fields will always be initialized to !null (discounting nullable types) in other languages structs are used to ONLY store data, in c# you can also put methods in them; if you supply an argumented constructor you need to make sure to initialize all fields
shorts are integers with a smaller range, -32,768 to 32,767
floats(also called single) have a range of -3.4 × 10 38to +3.4 × 10 38 with a precision of 7
doubles have a range of ±5.0 × 10 −324 to ±1.7 × 10 308 with a precision of (max) 16
Thanks for the thorough response, although I don’t know if any of that fits under the “explain to me like I’m 8” request lol. If you don’t mind doing a simpler description like “This number is really big! And his can have up to 10 decimal places. It is good for doing x, but inefficient for doing y”. Thanks
doubles: twice the power of floats; but thoroughly useless and generally overkill in realtime applications such as unity
shorts: less memory than ints but also less lower range; if you are not certain about the maximum range, stick to int
struct: use them to onlystore data; developing a good habbit that you can mirror in other programming languages
summary: stick to float and int, and use struct to hold data
Quoted for emphasis. This stuff (including very basic explanations) is readily available on Google.
It’s okay to come here with questions, but from what I’ve seen in the last week, it feels like you come here as your first last and only means of problem solving. The forum is not a replacement for your brain. A huge part of being a programmer is learning to think and research on your own. Possibly the only part of being a programmer.
Yeah I looked up structs and stuff online, but the explanations were filled with programming jargon that I didn’t understand. I also know that Unity has kinda changed a lot of stuff with their selected languages, especially JavaScript (as you its referred to as UnityScript) I was looking for a simple explanation that I knew was valid within Unity. Sorry if it seems like I wasn’t trying, and I’ll make sure to look extra hard from now on before coming to the forums
ah, don’t be too harsh on the kid; i myself was like that when i started to learn coding, bugging my mentor all the time about everything, but the more comfortable i became with the basics i suddenly reached a singularity where all the info i accumulated before compiled itself into a set of concepts and patterns and from that point onwards i was able to adapt to any problem in front of me. of course dragging him along the path might hinder his development towards that point but it’s also important to preDigest that kind of information in the beginning as to normal humans it would apear programming patterns are alien… go figure…
edit: just read your post and may i suggest you take the plunge and learn c# instead of javaScript, it may take a little longer to learn but will be well worth it.
I would say that structs in C# are used to store simple, lightweight objects such as Point, Color, Vector2 and the like. They can contain methods although I understand that this isn’t the convention in C#.
As for other languages (C++) the only difference between struct and class is the default access modifier. I follow the convention of using struct for types with no invariance and class for types that need to enforce invariance.
don’t worry about that; every new road you take is a dark and rocky one. and of course you’ll blindly stumble around in the beginning but the further you get the road will clear up and the sun will start to rise and all of a sudden you’ll find yourself on a nice walkway in bright daylight and can just stroll along having fun and picking berries from the bushes on the sides.
the most important part is persistence, stick to it and don’t get frustrated. for that to work you just need to set yourself small and easy goals.
when you have a goal write it down,
then underneath write down the detailed list of steps you think it’ll take to achieve that goal
then underneath that start a second list that you write as you tackle that goal and write the steps that actually worked.
when you reached your goal; take a little break and be proud of yourself… then take a look at the 2 lists. compare them and figure out why the 2nd list is different. Once you reach a point where the 2 lists match up; move to bigger goals.
repeat that process while you learn and work
another important tips is: when you’ve set yourself a milestone for the end of the day of what you want to achieve… and you achieve that milestone. be done. don’t start anything else that day. go to bed knowing that you achieved what you set out to do that day.
you may also want to write that milestone down at the beginning of the day, and when you reached it write down how long it actually took you.
and of course… take a breather every now and then… nothing is more corrosive to motivation like exhaustion.
That’s not actually true; all of it is the same as outside Unity. C# is C#, and while Unityscript is a custom language everything about shorts, structs, etc. is the same (conceptually if not necessarily syntactically).
Thanks man, I’m gonna print that out and put it on a plaque! You seem like a smart guy with a lot of experience. Its nice to have access to people like you on the forums. I don’t have a mentor so I guess that’s why I end up here a little too often