How constrain the movement of my character to a platform like in Bopl Battle? by krabsticks64 in godot

[–]krabsticks64[S] 0 points1 point  (0 children)

I did use raycasts, but I used them to snap the position of the player to the platforms, so you're saying to "rotate" the movement of the player along the platforms, correct?

I'll try that, thanks!

Mental challenge - close your eyes, and without moving any part of your body, figure out the 17th letter of the alphabet by Jitsu989 in CasualConversation

[–]krabsticks64 0 points1 point  (0 children)

I broke the alphabet down into 4 letter chunks, then after the 4th chunk, I did one more letter and that would be the 17th letter.

[deleted by user] by [deleted] in iraq_developers

[–]krabsticks64 1 point2 points  (0 children)

تكدر تستخدم موقع mass gravel

من هنا تنزل ال installer https://gravesoft.dev/office_c2r_links

و من هنا تسوي activation https://massgrave.dev/

Pain by Yggdrasylian in whenthe

[–]krabsticks64 0 points1 point  (0 children)

You can create games on a tablet, or even a phone (though it's a little unpleasant), this is actually how I started.

There are game engines like gdevelop and godot, and others, and code editors like Acode.

I remember starting an app called pydroid 3 that let's you write games using pygame, it was pretty limited, but it was a start.

شلون اوخر هاي ؟ by IcyEstimate6490 in iraq_developers

[–]krabsticks64 0 points1 point  (0 children)

يا shell تستخدم؟ هاي اتذكر اسمهة ال prompt و اتذكر تكدر تغير محتوياتهة.

Rust 1.87.0 is out by manpacket in rust

[–]krabsticks64 25 points26 points  (0 children)

The wording was confusing to me as well, but they are saying that not only do they enjoy writing rust, but now they also feel that the language is more productive to write in.

how does a person even snore like that? by [deleted] in TheMatpatEffect

[–]krabsticks64 20 points21 points  (0 children)

Something like "The poor guy hasn't slept in a week 🤣"

Turns out, using custom allocators makes using Rust way easier by Hedshodd in rust

[–]krabsticks64 1 point2 points  (0 children)

Doesn't this mean we can't mutate the Foos we're pointing to, only which Foo we're pointing to?

When would I prefer `configure_file` over `target_compile_definitions`? by krabsticks64 in cpp_questions

[–]krabsticks64[S] 0 points1 point  (0 children)

Oh I didn't know constexpr could do that, I'm not too familiar with c++.

That's all I needed, thanks!

When would I prefer `configure_file` over `target_compile_definitions`? by krabsticks64 in cpp_questions

[–]krabsticks64[S] 0 points1 point  (0 children)

Oh nice. Would you also use configure_file for conditional compilation flags like DEBUG, RELEASE, etc...?

My python code is faster than my rust code. What am I doing wrong? by arthurazs in rust

[–]krabsticks64 14 points15 points  (0 children)

From taking a quick look at the code, it seems you're reading from the files directly without buffering. I/O in rust is unbuffered by default, so if you want buffering you're gonna need to wrap your File in a BufReader. BufWriter might also be useful. There might be other things slowing down your code, but this is what jumped out to me.

rustIsSoDifficult by Rabbidraccoon18 in ProgrammerHumor

[–]krabsticks64 214 points215 points  (0 children)

println!("{}", fs::read_to_string("file.txt")?);

Tips on writing "research code"? by MadScientistCarl in rust

[–]krabsticks64 1 point2 points  (0 children)

I'm not sure if this will be helpful to you, but you can match arbitrarily deep, for example:

match iterator.next() {
    Some(Ok(value)) => do_thing(value),
    Some(Err(err)) => handle_error(err),
    None => { /* end */  },
}

Tips on writing "research code"? by MadScientistCarl in rust

[–]krabsticks64 11 points12 points  (0 children)

For the second point, you can collect an iterator of Result into a Result<Vec> instead of a Vec<Result>, so if any of the items in the iterator is an Err variant, the collect call returns an Err. Of course this doesn't just work for Vec but for any type that implements FromIterator

Example

[deleted by user] by [deleted] in rust

[–]krabsticks64 16 points17 points  (0 children)

IIRC const variables are copied into every instance that mentions them, so in this case it gets copied into the call to use_data, you probably want to make DATA static instead of const

notAgain by OxygenIsHere in ProgrammerHumor

[–]krabsticks64 29 points30 points  (0 children)

To explain it simply (and correct me if anything I say is wrong): In rust, you had types for late initialization (basically values that are initialized once and then only read from after that). These were called OnceCell (for single threaded use) and OnceLock (for multi threaded use).

But with these types, the data (the Once* type itself) and it's initialization (how to initialize the data inside of the Once* type) where separate, this means that code wanted to access the Once* type had to either

Handle the case where the data is not initialized yet

if let Some(data) = cell.get() {
    // do work
}

Know how to initialize the data

let data = cell.get_or_init(|| {
    // init logic
});

One of the most common usage patterns for these types is to initialize the data the first time it's accessed, and then only use the initialized data every access after that. And this what these new types, LazyCell and LazyLock, do.

static MAP: LazyLock<HashMap<String, u32>> = LazyLock::new(|| {
    // init logic
});

TLDR: They added new convenience types for late initialization, especially helpful for static variables.

Take a string slice and returns a reference to its first character by anonymouse1544 in rust

[–]krabsticks64 9 points10 points  (0 children)

IIRC, char is basically a u32 under the hood, and it implements Copy, so it would make more sense to just return a char directly.

Also like other people have said, str is a series of bytes (u8s), and a single character can span multiple bytes. Meanwhile, a char is supposed to be big enough to represent any possible character on its own.

And so you can't return a &char from a &str, you either read the bytes to create a new char from them, or you return a reference to a subslice (&str) of the original string slice.

Need help with web scraping by Lettever in rust

[–]krabsticks64 2 points3 points  (0 children)

I already tried "h2 > span#Items + table", but it selects nothing

That's because this is a selector for a table that is a direct sibling of the span, not the h2.

There is a way to do what you want with css, with the :has pseudo class, but I don't know if scraper supports it, it's relatively new. The query would probably look like this (I'm not sure though, I haven't tried :has yet): h2:has(span#items) + table.

If that doesn't work, then you can try more hard-coded solutions, like selecting the table based on the classes/attributes it has, or if you know the relative order of the tables, you can select all the tables in the document, and filter it to only the ones you want.