# Is C# easier to learn than C++?

**URL:** https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504
**Category:** Development Help
**Created:** [March 10, 2020, 8:15pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504 "2020-03-10T20:15:00Z")
**Posts on this page:** 20
**Page:** 4

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 25, 2021, 6:55pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/61 "2021-04-25T18:55:05Z")

</div>

By “read and write”, I mean that I can’t actually enter multiple lines in a single file unless I hypothetically use the ‘\n’ character literal.

Oh wait!

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [April 25, 2021, 7:08pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/62 "2021-04-25T19:08:27Z")

</div>

> **[StringBuilder Class (System.Text)](https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder?view=net-5.0)**
>
> Represents a mutable string of characters. This class cannot be inherited.

---

<div class="post-metadata">

### Author: ![Elrakrez](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/elrakrez/32/6404_2.png) [@Elrakrez](https://community.revolutionarygamesstudio.com/u/Elrakrez)
#### Post date: [April 25, 2021, 7:39pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/63 "2021-04-25T19:39:59Z")

</div>

I think this may help: [(c = getchar()) != EOF in C#? - Stack Overflow](https://stackoverflow.com/questions/4214794/c-getchar-eof-in-c), since that’s what cat does when it isn’t given any files to read. (It reads everything from stdin (the user input) until it receives EOF (by pressing ^D)).

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 25, 2021, 7:47pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/64 "2021-04-25T19:47:46Z")

</div>

A question: imagine I’m editing a file. I want to specify the index of a string with my cursor position. Not my mouse cursor, but where my “text” cursor is located within the current string.

Update: I’m using the `Append()` method for StringBuilder within a while loop. It works fine except that the very first character of everyline is always ignored.

Sample text:

```
// new line
ey, I'm Jon Doe. What's your name?
'm Jane Doe. How was your day?
 don't know because all of this is a test made by a newbie programmer.

```

Sample text from cmd:

```
Hey, I'm Jon Doe. What's your name?
I'm Jane Doe. How was your day?
I don't know because all of this is a test made by a newbie programmer.

```

Here’s the relevant piece of code.

> **Summary**
>
> ```
> Console.WriteLine("Please enter whatever you like.");
> while(true)
> {
> if (Console.ReadKey().Key == ConsoleKey.End)
> {
> break;
> }
> 
> sb.Append('\n');
> sb.Append(Console.ReadLine()); // seems to ignore the first character of each line and doesn't create a new line
> content = sb.ToString(); // hypothesis: perhaps it simply needs some help to create a new line.
> }
> 
> File.WriteAllText(filePath, content);
> 
> ```

Please ignore the comments as they aren’t relevant anymore. Now, it can create a new line. It just always ignores the first character of each line.

Oh wait!

Ah, nevermind. I thought that using `AppendLine()` would solve the issue, but no.

* * *

I’m really tempted to try and start learning more C# with Godot 2D. I’ve downloaded Godot Mono 3.3. I’ll share what I’m learning once more.

Source:

> **[Step by step](https://docs.godotengine.org/en/stable/getting_started/step_by_step/)**
>
> This series builds upon the Introduction to Godot and will get you started with the editor and the engine. You will learn more about nodes and scenes, code your first classes with GDScript, use sig...

# Nodes

So nodes are some kind of entities that can perform various processes. They have properties and they can also have children, which can form a tree. So nodes are kinda like classes but not necessarily for programming?

# Scenes

Scenes are basically a bunch of nodes. More on that later.

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [April 26, 2021, 6:48pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/65 "2021-04-26T18:48:19Z")

</div>

> [@blackjacksike](#):
>
> `// seems to ignore the first character of each line and doesn't create a new line`

You are calling

> [@blackjacksike](#):
>
> `Console.ReadKey().Key`

Which probably eats the first character. You need some other way to check for end of input.

You could have debugged this issue yourself if you had put a print or breakpoint after doing a `Console.ReadLine` and printing what that outputs. That tells you where the problem is:

- Either the ReadLine result is incorrect, and you know that the problem is there
- Or alternative if the ReadLine result is correct, then the later code is a problem.

This way you can quickly bisect your program to find where a problem is.

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 26, 2021, 7:45pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/66 "2021-04-26T19:45:37Z")

</div>

You were right! Using the End key condition at the start of the loop wasn’t good albeit that’s not what you suggested. I put it at the end of the loop and now it only seems to eat the first character of the last line. I do need however a new method of ending the edit. Perhaps calling a custom command could solve it.

YES!

```
while(true)
{
    sb.AppendLine(Console.ReadLine());
    content = sb.ToString();

    if (content.Contains("$end") == true) // if the string contains the command '$end'...
    {
        content = content.Remove(content.IndexOf("$end")); // then remove the first occurence command and everything following it
        break;
    }
}

```

Problem solved! Now, the only issue is that it modified the `content` string instead of modifying the `StringBuilder` object.

Anyway, me I’m big smart! Big brain!

OH YES sadsdksajd$#$#@J$NWL#WKEwK

`blackjacksike.exe` stopped working…

Rebooting…

Ah, here’s the solution!

```
            while(true)
            {
                sb.AppendLine(Console.ReadLine());
                content = sb.ToString();

                if (content.Contains("$end") == true) // if the string contains the command '$end'...
                {
                    sb = sb.Remove(content.IndexOf("$end"), sb.Length - content.IndexOf("$end")); // then remove the first occurence command and everything following it
                    content = sb.ToString();
                    break;
                }
            }

```

MATURED NEURON
  

 ![](https://static.wikia.nocookie.net/ancestors_gamepedia_en/images/e/e5/Neuronal_Branch_-_Intelligence.png)
  

INTELLIGENCE

# Processing

## Idle Processing

Done by using the `_Process(float delta)` method, which is called every frame. delta is the time variation, which can be used to multiply another variable.

## Physics Processing

Done by using the `_PhysicsProcess(float delta)` method, which is called every physical frame.

Question: How do I make the difference between each other? In the tutorial, it says movement could be used within `_Process()`, but then isn’t it a physical thing?

# Groups

Can be used for nodes with common features (e.g. allies, enemies, etc.).

# Overridable functions

`_Ready()` makes sure that all children nodes are active in a scene.

# Creating nodes with code

`_nodeName = new NodeName();`

Does it mean like `NodeName` is the parent or they just don’t explain it yet?

`_nodeName.Free(); // removes a node from a scene`  
`_nodeName.QueueFree(); // same thing but when it's safe`

# Instancing Scenes

```
var scene = GD.Load<PackedScene>("res://scene.tscn");
var node = scene.Instance();
AddChild(node);

```

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [April 28, 2021, 5:49am UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/67 "2021-04-28T05:49:20Z")

</div>

> [@blackjacksike](#):
>
> Question: How do I make the difference between each other? In the tutorial, it says movement could be used within `_Process()`, but then isn’t it a physical thing?

That depends entirely on if you use physics for moving or not. Thrive uses physics for moving so we need to do camera interpolation in \_PhysicsProcess to avoid jitter.

> [@blackjacksike](#):
>
> Does it mean like `NodeName` is the parent or they just don’t explain it yet?

No. NodeName there is just the class name of the node you want, for example:  
`new Spatial()` or in Thrive we have custom node classes like `new Microbe()`

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 28, 2021, 11:54pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/68 "2021-04-28T23:54:35Z")

</div>

Just in case this kind of thing happens albeit unlikely, how does licensing work? I mean, you can’t just create a project and say “Hey, it has the MIT license now!” Right?

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [April 29, 2021, 5:38am UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/69 "2021-04-29T05:38:16Z")

</div>

You in fact can. Assuming any third party code you used, doesn’t have restrictions on derivative works. For example if you use _any_ GPL code in your project, your whole project must be licensed under the GPL license.

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 29, 2021, 8:02pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/70 "2021-04-29T20:02:57Z")

</div>

By the way, in terms of 2D vectors, is there any math notions I should learn before doing complex things? Do I need to know matrices? Quaternions? Complex numbers?

---

<div class="post-metadata">

### Author: ![Evolution4Weak](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/evolution4weak/32/11005_2.png) [@Evolution4Weak](https://community.revolutionarygamesstudio.com/u/Evolution4Weak)
#### Post date: [April 29, 2021, 10:06pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/71 "2021-04-29T22:06:33Z")

</div>

Not really, i think just knowledge of vector math, like this tutorial can provide: [Vector math — Godot Engine (stable) documentation in English](https://docs.godotengine.org/en/stable/tutorials/math/vector_math.html)

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 29, 2021, 10:11pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/72 "2021-04-29T22:11:29Z")

</div>

So things only get weird when going in 3D, right?

EDIT: Eh, I think I’ll get more experience with basic C# instead.

Or maybe I just need to make a game without following a tutorial. That would be best, yes. That doesn’t mean I won’t make or update CMD programs anymore, though.

I think I’ll work on a Pong clone.

Update: I’m trying to call `Rect2.Rect2()` but it says that Rect2 doesn’t have a definition for that method.

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [April 30, 2021, 7:54pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/73 "2021-04-30T19:54:32Z")

</div>

Constructors aren’t methods. Also I find using an IDE or text editor with plugins that has auto complete for C# to be really nice to quickly see if what you are typing is a thing that exists or not.

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [April 30, 2021, 7:55pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/74 "2021-04-30T19:55:44Z")

</div>

Yeah, I just figured that it was a constructor, lol.

I’m trying to draw a rectangle and set it as a texture for a sprite.

Finally, I used a rectangle from Inkscape as a placeholder. Wouldn’t it be better to draw it instead? Imagine I implement an option to change the resolution, wouldn’t that be difficult to recompute the player’s rectangle size if it’s purely based on an image?

For some reason, when I use a key to move my player1 bar, it immediately goes up on top and on bottom when closing the game.

```
using Godot;
using System;

public class Main : Node
{   
    private Vector2 _screenSize;
    private Vector2 velocity;

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        _screenSize = GetViewport().Size;
        StartGame();
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(float delta)
    {
        if (Input.IsActionPressed("ui_up"))
        {
            velocity.y -= Convert.ToSingle(_screenSize.y * 0.25);
        }
        else if (Input.IsActionPressed("ui_down"))
        {
            velocity.y += Convert.ToSingle(_screenSize.y * 0.25);
        }

        if (velocity.Length() > 0 || velocity.Length() < 0)
        {
            GetNode<Area2D>("Player1").Position = velocity * delta;
        }

        GetNode<Area2D>("Player1").Position = new Vector2(
             x: Mathf.Clamp(GetNode<Area2D>("Player1").Position.x, Convert.ToSingle(_screenSize.x * 0.0328125), Convert.ToSingle(_screenSize.x * 0.0328125)), // Position.x is always the same
             y: Mathf.Clamp(GetNode<Area2D>("Player1").Position.y, Convert.ToSingle(_screenSize.y * 0.0625), Convert.ToSingle(_screenSize.y - _screenSize.y * 0.0625))
        );
    }

    public void StartGame() 
    {
        GetNode<Area2D>("Player1").Position = new Vector2(Convert.ToSingle(_screenSize.x * 0.0328125), Convert.ToSingle(_screenSize.y * 0.5));
        GetNode<Area2D>("Player2").Position = new Vector2(Convert.ToSingle(_screenSize.x * 0.9671875), Convert.ToSingle(_screenSize.y * 0.5));
    }
}
```

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [May 1, 2021, 8:07am UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/75 "2021-05-01T08:07:38Z")

</div>

`delta` is there for a reason. If you don’t use delta in your calculations, you are tying the game speed to framerate… and here if you have vsync on it takes 15th of a second to move entire screen size because you don’t take delta into account.

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [May 1, 2021, 2:58pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/76 "2021-05-01T14:58:57Z")

</div>

So using `GetNode<Area2D>("Player1").Position = velocity * delta;` isn’t enough? Interesting.

---

<div class="post-metadata">

### Author: ![hhyyrylainen](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/hhyyrylainen/32/32_2.png) [@hhyyrylainen](https://community.revolutionarygamesstudio.com/u/hhyyrylainen)
#### Post date: [May 1, 2021, 5:31pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/77 "2021-05-01T17:31:49Z")

</div>

Actually I didn’t read that far. That line is probably fine, but the speed or something else might be bad.

Also you are constantly calling GetNode in your code, that is very bad for performance. You should only call GetNode once in your \_Ready method.

---

<div class="post-metadata">

### Author: ![Elrakrez](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/elrakrez/32/6404_2.png) [@Elrakrez](https://community.revolutionarygamesstudio.com/u/Elrakrez)
#### Post date: [May 1, 2021, 6:58pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/78 "2021-05-01T18:58:07Z")

</div>

> [@blackjacksike](#):
>
> For some reason, when I use a key to move my player1 bar, it immediately goes up on top and on bottom when closing the game.

What do you mean by that? Do you mean the rectangle instantaneously goes to the top or bottom when pressing a key to move?

---

<div class="post-metadata">

### Author: ![blackjacksike](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/blackjacksike/32/7094_2.png) [@blackjacksike](https://community.revolutionarygamesstudio.com/u/blackjacksike)
#### Post date: [May 1, 2021, 6:59pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/79 "2021-05-01T18:59:37Z")

</div>

Kind of, but only at the beginning.

---

<div class="post-metadata">

### Author: ![Elrakrez](https://thrivecommunity-cdn.b-cdn.net/user_avatar/community.revolutionarygamesstudio.com/elrakrez/32/6404_2.png) [@Elrakrez](https://community.revolutionarygamesstudio.com/u/Elrakrez)
#### Post date: [May 1, 2021, 7:13pm UTC](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504/80 "2021-05-01T19:13:04Z")

</div>

I just noticed you aren’t resetting velocity. Since you are using the `+=` operator to set the velocity, the velocity will increase the longer you hold the key. Use `=` or set velocity to Vector(0, 0) at the end of `_Process`.  
Also, I think `velocity.Length() > 0 || velocity.Length() < 0` can be rewritten as `velocity.Length() != 0` or `velocity.y != 0`.

[Previous page](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504.md?page=3)

[Next page](https://community.revolutionarygamesstudio.com/t/is-c-easier-to-learn-than-c/2504.md?page=5)
