#I was wondering what peoples opinion is on this code?

1 messages · Page 1 of 1 (latest)

umbral wyvern
#

This isn't my code, and I haven't tested it, I have no idea if there are major errors or not, and frankly I'm too lazy to test right now.

#

That and I don't have any animations to test with it.

north vale
#

I would probably use local function if you dont need the functions to be a global variable

umbral wyvern
#

Good point, I guess I didn't even read :)

silk mural
#

another thing I would of done is load all the animations at the top of the script instead of when you call the playAnimation function

umbral wyvern
umbral wyvern
#

I asked ChatGPT to make this, which is part of why the script didn't use local functions.

#

I wanted to see how it would do with Roblox, since I've been using it in Rust for the past two-three days

silk mural
#

also you should not use the humanoid to load animations

umbral wyvern
#

Well now I'm just getting knowledge that I might need later :)

silk mural
#

also you should not use findfirstchild to get the humanoid

#

because it could return nil and make the script not work

umbral wyvern
#

Oops

#

Or handle the nil case with an if statement?

silk mural
umbral wyvern
#

wait for the humanoid probably, I'm not exactly experienced when it comes to Roblox

#

I'm sure there is some sort of something I'd probably have to do, because after death the humanoid gets replaced with a new one, doesn't it?

silk mural
umbral wyvern
# umbral wyvern I wanted to see how it would do with Roblox, since I've been using it in Rust fo...

I just finished using ChatGPT to write this sieve

use std::time::Instant;
use rayon::prelude::*;

fn is_prime(n: i64, primes: &[i64]) -> bool {
    !primes.iter().any(|&p| p * p <= n && n % p == 0)
}

pub fn run(upto: i64) -> Vec<i64> {
    let now = Instant::now();
    let mut primes: Vec<i64> = Vec::new();
    primes.push(2);

    let chunk_size = 1000; // Adjust the chunk size based on your system and requirements

    (3..=upto)
        .collect::<Vec<i64>>() // Collect the numbers into a Vec
        .par_chunks(chunk_size) // Split the range into chunks
        .flat_map(|chunk| {
            chunk.par_iter().filter(|&&i| is_prime(i, &primes)).cloned()
        })
        .for_each(|prime| {
            primes.push(prime);
        });

    println!("{}", Instant::now().duration_since(now).as_micros());
    primes
}

fn main() {
    let upto = 100000; // Change this to your desired value
    let result = run(upto);
    // println!("The prime numbers up to {} are: {:?}", upto, result);
}

On the machine I'm currently running on this completed running in 6 milliseconds, and it was made by ChatGPT

#

Oof

#

That's a bit bigger than I thought

#

I don't know what half of it means tbh

silk mural
#

i think chat gpt is not helping you

umbral wyvern
#

It's not

#

Fr

#

I need to get back to doing this stuff on my own

#

But that sieve would've probably taken me a ridiculous amount of time to get down to 6 ms, since I probably wouldn't have discovered the Rayon crate for quite a long, long time.

silk mural
#
local module = {}
local animations = {}

local function CharacterAdded(character)
    local animator = character:WaitForChild("Humanoid"):WaitForChild("Animator")
    table.clear(animations)
    for index, child in script:GetChildren() do
        animations[child.Name] =  animator:LoadAnimation(child)
    end
end

if game.Players.LocalPlayer.Character ~= nil then CharacterAdded(game.Players.LocalPlayer.Character) end
game.Players.LocalPlayer.CharacterAdded:Connect(CharacterAdded)

module.Play = function(name)
    if animations[name] == nil then return end
    animations[name]:Play()
end

return module
umbral wyvern
silk mural
#

you can put this in replicated storage

umbral wyvern
#

Are you opposed or for static typing?

silk mural
#

or did i not understand you?

umbral wyvern
#

I thought Luau that the uh --!strict typing mode

silk mural
#

oh but its not static

#

you can cast a new type when ever you like

umbral wyvern
#

Close enough for my friend to absolutely hate typing function arguments

silk mural
#
local part = Instance.new("Part")

local changedType = part :: CFrame
#
local notACFrame = Instance.new("Part") :: CFrame
#

but your correct this wont work with --!strict

#

I personally don't use type checking

umbral wyvern
#

Thanks for your feedback Suphi, this has been quite a fun experiment