#I was wondering what peoples opinion is on this code?
1 messages · Page 1 of 1 (latest)
I would probably use local function if you dont need the functions to be a global variable
Good point, I guess I didn't even read :)
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
Hi Suphi, thing is I'm ready to let the cat out of the bag
ok lets see it
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
also you should not use the humanoid to load animations
Well now I'm just getting knowledge that I might need later :)
also you should not use findfirstchild to get the humanoid
because it could return nil and make the script not work
instead use WaitForChild?
Oops
Or handle the nil case with an if statement?
how will you handle the nil case?
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?
this script is placed in startercharacter so it will run every time the humanoid is spawned
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
i think chat gpt is not helping you
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.
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
Thanks, you don't have any IP on that right?? jk
you can put this in replicated storage
Are you opposed or for static typing?
lua does not have static
or did i not understand you?
I thought Luau that the uh --!strict typing mode
Close enough for my friend to absolutely hate typing function arguments
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
Thanks for your feedback Suphi, this has been quite a fun experiment