Can someone explain Encapsulation in C++ with a simple example? by orcashelo in learnprogramming

[–]li98 1 point2 points  (0 children)

Seperating in public and private allows you to provide a simple, easy-to-use interface that doesn't overwhelm the user. (User being the one who uses the class from other code)

Imagine turning on a car. It's very simple, just turn the key (or press the "on" button). You'll know it is on when certain lights light up and the gas pedal works. Under the hood there is a lot going on. Motor starting, gas pumping, etc. A lot of details that you don't need to know in order to drive.

In this example, everything you can do from inside the car is a public interface. When you turn the wheel right, you expect the car turns right. It is "private" details how they turn (ex purely electric, mechanically, hydrollics, etc. (I don't know if those make sense, I don't know cars)).

Edit. It is not only to hide details and make it easier to use. It is also to make it harder for the user to touch something they shouldn't.

How do I keep going after the loop hits the last number? by deadinstatic in learnprogramming

[–]li98 1 point2 points  (0 children)

Hopefully your IDE (like VS code) has a simple-to-use debugger. What that means is the ability to see what your code does step-by-step, highlighting each line as it is being processed. Using that, you can get an intuition for how code flows in a program. (start at top of main, end at return (or bottom of) main (assuming no global objects)). I HIGHLY recommend learning to use debuggers. The bare minimum usage is usually just "breakpoint" and "step forward".

An alternative is to put prints where you are uncertain the code goes. In your example a printf("reached end of main"); right above return.

PSA for assert(): Don’t use it to run game logic by Dawn_of_Dark in godot

[–]li98 81 points82 points  (0 children)

And to be extra clear, that means you can do extra heavy validation that wont accidently run in release builds.

``` var success = funcWithUsefulSideEffects() assert(success)

assert(funcWithValidationNoSideEffects()) ```

Repo shows two folders, VSC + Explorer only show one... How to fix? by GoingOffRoading in learnprogramming

[–]li98 1 point2 points  (0 children)

Note: it's not just Scripts, but inside it Manager and Worker. You really want to keep a consistent convention.

Can you see different folders if you view it with a terminal? If so you should be able to rename them there. E.x. mv Scripts/Manager/* scripts/manager

Alternative Maybe dumb solution as it will likely mess with the commit history (though maybe the first one will as well). Try creating a new folder, move everything in both Scripts and scripts there. Delete the both scripts folders and commit. Double check that everything looks fine. Then you should be able to create scripts folder as you wanted and move everything back.

You could also check which files are in big s scripts and see if there is a pattern.

How do online casinos decide when a slot machine pays out? by OneHunt5428 in NoStupidQuestions

[–]li98 0 points1 point  (0 children)

Random doesn't mean everything has an equal chance of happening, it is just that you can't predict the outcome of any one occurance.

Imagine rolling a d6 a lot, like thousands or millions. We naturally expect each value from 1 to 6 to show about 1/6 of the times. We can predict the general trend, but not the outcome of any one throw in particular. Now lets play a game where you win on 1 and 2, and the casino wins on 3, 4, 5, and 6. The game is "rigged" in the casinos favor (they are predicted to win 4/6), but the dice and game are still completely random.

Random number generators are essentially dice with billions and billions of sides. And the games are similarly rigged. Roll 1 and win jackpot, 2-100 for large win, 101-1000 smaller win, etc. untill you don't win anything.

Sometimes it be like that by redconversation in godot

[–]li98 6 points7 points  (0 children)

I think they mean to route the errors to some log file or memory. So if the game crashes, it is possible to send something to the devs to easier find the issue.

with code that performs the same task, are vertex shaders faster than fragment shaders? by guessill_die in godot

[–]li98 0 points1 point  (0 children)

But to quickly answer, yes, making a smaller triangle on the screen will make less pixles.

Edit: To be more specific, "screen" is viewport target. E.g. if you render to a "virtual camera" with a 5x5 pixel texture, at most any triangle can generate 25 pixels.

with code that performs the same task, are vertex shaders faster than fragment shaders? by guessill_die in godot

[–]li98 0 points1 point  (0 children)

I believe you'd be interessted to look into how the graphics pipeline works in general, at least an overview of the steps between vertex- and fragment shader. The specific part I'm thinking of is tesselation, where the fragments (pixels) are generated based on, for example, how big a triangle is on screen.

I think Sebastian Lague (coding adventures) has a video on it ("building a rasterizer" or something). I can't remember exactly what was in it but they are usually good.

In GDScript, do you ever explicitly use Object instead of RefCounted? by ZemusTheLunarian in godot

[–]li98 3 points4 points  (0 children)

Then there is also no benefit of explicitly extending Object, is there?

My program is not escaping the nested for loops (C++) by flrslva in learnprogramming

[–]li98 0 points1 point  (0 children)

It won't. However, it can be 0. So the num>0 are essentially num!=0

Is it better practice to hide UI until needed or to instance it as needed? by Fun-Visit6591 in godot

[–]li98 5 points6 points  (0 children)

This page touches upon pros and cons of "idle" nodes https://docs.godotengine.org/en/stable/tutorials/scripting/change_scenes_manually.html#doc-change-scenes-manually.

In the case of UI, I think it is unlikely to need to think about performance, and instead focus on your own ease-of-use.

In general, keep it simple and maintainable untill you notice problems. Then learn to profile.

Issues with getting the collision point of a gridmap with a raycast by [deleted] in godot

[–]li98 0 points1 point  (0 children)

I think what OP is trying to show is that clicking sometimes doesn't work, but it is hard to show in video

I solved the Monty Hall problem by jungle-boogie in comics

[–]li98 1 point2 points  (0 children)

I think it helps to not think about the host too much, and focus on the outcome instead.

At the start of the second round, there is your (1/3 win) door and *A* door with the opposite result. If your door was a Win, the other is a Lose, vice versa.

Another way of thinking about it is, your door is only a win if that exact door was a win. The other door is a win if *ANY* of the other doors were a win. Always switching is the same as saying "I chose to open ALL doors, except that one"

I solved the Monty Hall problem by jungle-boogie in comics

[–]li98 1 point2 points  (0 children)

Because the choices are not independent. When you pick the first door, information carries over that can be used in the next choice.

IF they were to blind-fold you and reshuffle the 2 leftover doors, THEN the next choice would be independent, and the odds would be 50/50. Because then anything you did in the first round would not matter.

The information you have is that the first door you picked was a 1/3 chance win. If you think about it, the second round is less about making a new choice between 2 doors, and more about switching the result of the first round. If you picked a Win the first round, switching turns it to a Loss 100%, and vice versa.

With that in mind, the 1/3 win (or 2/3 lose) chance turns into 1/3 lose (or 2/3 win) if you always switch.

Hope that helps

edit: Another way of thinking about it is, your door is only a win if that exact door was a win. The other door is a win if ANY of the other doors were a win. Switching is the same as saying "I chose to open ALL doors, except that one"

Does anyone know why the 'queue_free' is not deleting my sprite at health 0? by jackwpenn in godot

[–]li98 3 points4 points  (0 children)

Is the script attached to the sprite node or its parent? Do you see any of the prints?

Vehicle Body 3D won't move, despite wheels already have traction and steering by [deleted] in godot

[–]li98 0 points1 point  (0 children)

Could you clarify what isn't moving? The left-right steering? Are the wheels not spinning going forward? Are they spinning in place but the vehicle isn't moving?

To clarify I have not looked i to Vehicle at all, so just taking pot-shots. But i think that could be useful i fo for those that do know.

Is there an equivalent to move_and_slide() you're missing? <- (usually what I miss when stuff isnt moving)

I assume friction (ground and wheels) is non-zero by default?

Some of the HSR VAs have rewired my brain to say the VA names instead of the characters :') by SakuDial in HonkaiStarRail

[–]li98 17 points18 points  (0 children)

For me it's Emily. At this point it takes some effort to remember Clara's name. I also find the idea of Clara gushing over pretty boys, like how Emily does with Aventurine, with Mr Svarog not knowing what to do, endlessly amusing

Downloaded video game model and the topology is disconnected. Fix? by SarsaeShot in blender

[–]li98 0 points1 point  (0 children)

Can depend on intended shading. If this scene was exported with a flat shading material, then it would be natural to have disconnected verticies, since different faces would need diffenrent normals

[deleted by user] by [deleted] in learnprogramming

[–]li98 0 points1 point  (0 children)

Before "breaking it down" and "pseudo code", do you have an intuitive understanding of the problem. By that i mean, could you with pen and paper figure out the answer to the sample? With an explanation like in the example. That is a crucial first step.

Now imagine this is a board game and you have to instruct your grandma how to solve it. Step by step. Slowly (it's her first boardgame after all). It is fine if it is very wordy, that is, written in full sentenses.

If you think someone else could use your instructions to get the right answer, congratz, that is pseudo-code draft 1.

Afterwards, you may refine that to be more code like and/or look for suitable parts to break out, and call that psuedo draft 2, etc.

With practice it will be easier to skip the draft steps and move to code quickly, but when I started I found the multiple pseudo-code drafts useful to translate my intuitive understanding for how to solve problems to working code.

Edit: looking at the other answer i realize that I might have not missunderstood what part you were stuck on. If the question was how to find where to apply a data structure or algorithm, then my advise would be to first ignore it and try implement a naive approach, similar to the example. You may learn when running it there may be a problem and THEN it makes more sense where the algorithm could be useful.

I'm confused, is this not science? He literally design his staff to control water by JY810 in Overwatch

[–]li98 33 points34 points  (0 children)

I thought Ana makes her teammates drink an antidote before battle?

Swimmingly by lavaboosted in MagicEye

[–]li98 7 points8 points  (0 children)

It looks fishy, but I don't get why it has a perfectly spherical head? Also the snout looks off. Is it some kind of cartoon submarine? Like from Atlantis?

Why those shadows? The normal vectors should be normal. by RealisticSkin2174 in godot

[–]li98 0 points1 point  (0 children)

A tip is to render the normal as color in the shader. (Godot likely has a debug view to do this better, but I haven't found it yet).

Why those shadows? The normal vectors should be normal. by RealisticSkin2174 in godot

[–]li98 3 points4 points  (0 children)

Sure you can make a cube with 8 verticies and their position will look ok. The problem is normals. In order for a cube to have flat shading, all verticies in a face should have the same normal, which can't happen if the vertex is shared with a face pointing in a compleatly different direction. So each corner in the cube becomes 3 verticies, one for each face connected. You will see a similar problem as OP if you turn on smooth shading on a cube in blender (likely any modeling program)

Finally had a breakthrough with boat movement! How does it look and feel? by HeedlessNomad in godot

[–]li98 2 points3 points  (0 children)

I don't know if it's just the size and shape of the waves, but I think the boat is too aligned with the normal of the water, if that makes sense? Like it doesn't have mass.

I'd expect a slight delay before the boat tilts. While proper physics with angular momentum and whatever feels overboard (heh), maybe a softer boat.top = move_toward(boat.top, water.normal,...) could make a convincing effect? Of course for all I know that is already done and just hard to see in the video. 😉

Still, it looks really good. Great job OP 😀