r/AskProgrammers • u/Severe-Sport5635 • 2d ago
Need advice to code...
I've been learning c# for unity and looked up multiple tutorials learning basics to intermediate. I've completed the tutorial part from w3 schools and various tutorials right now following the code monkey free course on YouTube.
I can understand the code when I look at it and tell what happens in a particular that code block.
But the issue I'm facing is not being able to write it on my own without any help from AI or having a heads up.
It would be of great help if I could get some piece of advice on how to actually learn and know stuff and be able to write code on my own...
4
4
3
u/Individual-Show9181 2d ago
Stop watching tutorials and start building real games. The best way of learning is by failing and trying to solve a problem for hours.
2
u/Gznork26 2d ago
Solving the problem you've been set and turning that solution into code are two different skills. You've been learning the latter.
It might be useful for you (as it had been for me) to first address the problem, and leave the code part for later. Any problem can have one solution, many solutions, or none at all. Assume that it might have many, analyze it in various ways, and for each one sketch out the steps you'd have to take to get there. Instead of doing this with code, use what's called pseudocode, a human-readable set of logical steps (of any size) with branches as needed. Once you have generated some number of possible ways to approach the problem, compare them to assess which is the simplest to implement using the language you've chosen to code it with. And finally, write the code in broad strokes, creating blocks for each stage of the procedure, and then fleshing each one out, and breaking it as needed into smaller steps.
In the languages I've coded with, my style was to first lay out the problem using comment blocks, and then insert the operative code, using temporary write statements to expose the steps as they are executed. If you determine that there are parts of the solution that the language is ill-suited to, perform the same procedure with another of your solutions. Those trouble areas might be better addressed by calling a library procedure or even using a second language for part of the solution.
Once you have a functional solution, look for ways to improve each part.
For me, solving the problem was the best part of the job, and implementing it in code was less stressful. (YMMV)
1
u/ragebunny1983 2d ago
Write some small python scripts to help with real life things. basically most things you would use a spreadsheet for you can do in code and it's the next step after a spreadsheet gets too unwieldy.
I made a script to randomly allocate christmas present buying duties to different households in the family (so we could save some money and just get the adults one big present each). I also made one that did a house chores rota and emailed me and my gf who's turn it was to clean certain areas of the house. Then I made it run on a cronjob on my raspberry PI every week.
Often when you get into it you find there is a bit more to it than you think and it's quite fun.
1
u/GlassboundIllusion 2d ago
It would be of great help if I could get some piece of advice on how to actually learn and know stuff and be able to write code on my own...
You learn to write code on your own by writing code on your own.
If you have to, go back to Hello World and work your way up. Start small, complete a project or exercise, then move on to something slightly bigger.
It's okay to reference for syntax, you can even ask the AI for the syntax, but make sure you've instructed it not to suggest you any extra information you haven't asked for it.
The only time you need to have the exact syntax memorized is for taking certification exams. Every other time, most programmers are relying on autocomplete or googling things anyway. You'll start to remember some of it through sheer repetition of typing it out or copying and pasting it anyway,
The big thing is that you're one deciding how to write it, that you run and test it yourself, and that you troubleshoot it yourself.d
1
u/Ordinary_Variable 2d ago
Make your own template by taking a "hello world" and including a lot of lines of examples of doing certain things.
Most coders have a toolbox of code samples they've used in the past. Very few coders actually sit down and type it all out every single time.
I have an HTML with some canvas, some buttons, some formatting, etc. When I start a new project I copy and paste the file and remove the lines I don't need and duplicate the lines I will need more of. I'd love to share it but I don't know if I can share files here.
1
u/simonsmine 2d ago
Break out a debugger, make sure to hookup vs studio / vscode or whatever the jetbrains ide is for Unity. Put in a breakpoint and inspect what the callstack is like. Its a long journey but pausing and actually looking at the call chain will teach you a lot
2
u/EngineersUniverse 2d ago
Understanding code and writing it from scratch are different skills. Watching someone cook makes sense too, but suddenly you’re alone in the kitchen googling “is smoke an ingredient?” 😂
Try building something tiny in Unity: a button that increases a score, a door that opens, or a coin you can collect. Before coding, write the steps in plain English. For the coin: detect the player → increase score → remove coin. Then tackle one step at a time.
When you get stuck, look up that specific problem. If you use AI, ask for a hint or an explanation before asking for the solution. After getting it working, close the reference and try rebuilding it yourself. Then change something so you have to think through it.
You don’t need to memorize every method.
The skill you’re practicing is breaking “I want this to happen” into small steps you can implement. A tiny finished project will teach you a lot.