More Rust and the return to Godot?

More Rust and the return to Godot?

First up, gonna be working through more of this Rust course, really enjoying it actually. I quite like the way this language works so far, seems to click in my head. We'll see how I feel by the end of the course, though.

After 2 sections of this course I think I will just try to implement the character controller in Godot. I think that I figured out what I needed to by messing around with Unity. I never really liked it, not to say it is a bad engine but it really just doesn't work for me. I was thinking about dumping it for Monogame the whole time, though that's a whole new can of worms. If I was going to go for Monogame, why not just SDL and write my own toolchain? Then I figured... learning Rust... maybe I should do that as a learning project? Who knows, I am still trying to find my bearings and get a direction here.

What I do know is that it might be a good idea to get in Game Jams and you know, I am really productive with Godot, I like Godot. It would be several more months of bashing my head against Unity, disliking it the whole time or I could just go back to Godot and make the move into Unreal when I go to 3D. Maybe Godot 4.0 will be out by then and I wont need to jump engines at all. Maybe I will be able to improve the 3D rendering in Godot myself by then, due to familiarity. Maybe GDNative will be well documented by then. If not, I got a plan B, C and D.

So the next prototype will be Godot-based. It's likely going to be some form of Turn-Based RPG system inspired by Earthbound and based in Surrealism. I can't say for sure, though. I will probably use 16x16 as my resolution for most of the sprites and tiles to keep graphics simple so wherever I need to draw sprites I can do so in like 10-15 minutes.

Anywho, on to the coursework.

And I expected this to be a boring section about control flow.

//Awesome thing here. The If statement is an expression!
    let sound = "Woof!";
    let animal = if sound == "Meow"{"cat"}
                        else if sound =="Woof!"{"dog"}
    println!("I heard a {}, must be a {}.", sound, animal); // Woof!, dog

Evaluating an if statement as an expression is pretty fucking awesome, though. It's like a more readable ternary expression.

Also I have been a pretty big fan of Jetbrains software through the years, really not regretting my Clion purchase. It combined with the Rust docs really makes learning Rust a lot easier than I had expected. Check out this functionality.

It even has examples. Magnificent.

Also check out that range operator. 1..11, 20..42. Pretty sweet, actually. I know you can call functions or write functions to generate ranges but this is pretty good if you have to do a shitload of ranges in rapid succession. You'd be surprised how often I find myself in that position.

I don't want to get too ahead of myself with Rust here but it really is shaping up nicely so far.

There is also syntax for an inclusive range,

1..=100 // 1-100(Inclusive)
1..100 // 1-99

There's a lot of interesting ways to do things in Rust. Stuff I will probably forget about and end up doing the hard way, just based on what I am used to.

match x{
            0 => "Nonw",
            1|2 => "one or two",
            12 => "a dozen",
            9...11 => "a lot",
            _ if (x % 2 == 0) => "several",
            _ => "some"

The way match statements work is not just like a normal old switch. There's some interesting filtering available from within. I am guessing this is because all if not most things are expressions and expressions are evaluated ahead of time in compilation? I am wondering how this would work with memory safety when dynamic values come in, though I am sure it's more clever than how I am seeing it. Match is also able to be used as an expression (is there anything you can't use in this way?).

let my_new_arr = [1u8;10];

Array definition is a bit strange, it will certainly take some getting used to. The above code fills the array with 10 u8 integral values that are all 1.

The way Options work is also quite interesting, it is like some advanced bool.

 // Option<T> and if let, while let.
    let my_val = 3.0;
    let other_val = 1.0;
    // result is an Option and either contains Some and a value or None.
    let mut result = if other_val != 0.0{ Some(my_val/other_val)} else {None};

    // Test comparison. Can be Some(With Val) or None.
    // Like an advanced Bool.
    match result{
        Some(z) => println!("{}/{}={}", my_val, other_val, z),
        None => println!("Error! Can not divide these numbers.")

    // Treating it like a bool works with if let
    if let Some(z) = result{
        println!("Result = {}", z);

If there is no value, it's basically false(None) and if there is a value it is that value. Clever, I think.

It has Unions which... I try and avoid in most situations. Schrodinger's Type is a pain in the ass sometimes in debugging. Expect an int, get a float... better bust out the break points, boys!

It's got some crazy ass Enums as well.

    enum Color{
        RgbColor(u8,u8,u8), //Can have more than just basic enums
        CmykColor {
            // Can also use a struct in here.
            cyan: u8,
            magenta: u8,
            yellow: u8,
            black: u8
    let c:Color = Color::RgbColor(1,2,3);

They aren't just aliases for numbers, they have functionality. Fancy.

It's 4:30pm now, I ended up having to take some time to lay down... I ate too much rice for lunch and my body and mind became sluggish. It's no use trying to learn in that state, I just get frustrated and progress is slow and painful. I've really gotta remember to keep lunch light from now on.

I just noticed it's Friday. Holy shit. I guess it was an alright week if I didn't notice it passing. Cool.

From here on I will only be doing a section of course per day (Unless the section is really short), I think that's a reasonable rate and I do at least some a day, while having time for projects in the later half. I've got some stuff to do with Mantilogs, like the temperature logging nodes v3. Gonna get started on that next prototype next week too. The next course will be Blender related, then either some CAD software or ethical hacking. I should probably be starting the next course around the end of this month/beginning of next month. Hopefully having some idea of a Rust project to keep on learning with.

Well, time to make some dinner and relax for the night. I will keep doing courses on weekends unless I am feeling worn down, so I might post tomorrow with more things I find interesting about Rust.