#How do I organize/optimize this better?

1 messages · Page 1 of 1 (latest)

torn plaza
toxic jetty
#

you can

#

very much

#

you can just set the attribute for the endtime of stun

torn plaza
toxic jetty
#

and to check if theyre in the state just compare current time to endtime

#

then u can boom the heartbeat check

torn plaza
toxic jetty
#

delete

#

u dont need the heartbeat connect

#

and for handling stun you can do it on client

#

as in

#

the walkspeed

#

that way u can nuke a relatively expensive heartbeat server connection

torn plaza
toxic jetty
#

they can change their walkspeed anyway

#

doesnt matter what the server says

#

@torn plaza

torn plaza
toxic jetty
#

attributes use a hashmap so lookups are O(1)

torn plaza
# toxic jetty wdym

Using attributes is less optimized than using arrays cuz they have to pass through the lua - c++ layer, no?

toxic jetty
torn plaza
toxic jetty
#

also you should just be able to assume state is "idle" if the endtime of last state is less than current time

toxic jetty
torn plaza
torn plaza
toxic jetty
torn plaza
#

Is my m1 system fine

toxic jetty
torn plaza
toxic jetty
#

@torn plazaalso I tested it just now

#

attributes are a bit slower than indexing an array

#

but

#

it doesnt matter

#

this is for 50000000 lookups

arrays (top)
attributes(bottom)

torn plaza
#

Since I’m mainly iterating through an array I don’t think it’s that expensive

torn plaza
toxic jetty
#

Since the stun will end the exact time intead of having to replicate the walk speed change

torn plaza
#

@jade kindle can I get ur opinion

torn plaza
#

@jade kindle i need this gng

sacred horizonBOT
#

studio** You are now Level 14! **studio

torn plaza
#

@vocal walrus u got me tho right

vocal walrus
#

wat

vocal walrus
jade kindle
#

Sry I’m busy

torn plaza
vocal walrus
#

second; your code is pretty bad

#

you're optimizing bad code

#

.... get your code right first, before you make it fast.

torn plaza
vocal walrus
# torn plaza How is it bad

well for starters you don't clean up entries in M1IndexMap or M1Characters so they will build up forever without limit, this is a memory leak.

torn plaza
vocal walrus
#

second this does not scale ```lua
local M1Character = {}
local M1Debounce = {}
local M1Number = {}
local M1IndexMap = {}

vocal walrus
#

its not flexible enough to build on it

torn plaza
vocal walrus
#

3rd ```lua
RunService.Heartbeat:Connect(function()

for i = #StunnedCharacters, 1, -1 do
#

4th ```lua
function module.HitVFX(char)
local att = vfxpart.HitVFX:Clone()
att.Parent = char.Torso
att.Hit:Emit(10)

game.Debris:AddItem(att, 0.4)

local SFX = game:GetService("SoundService").punchSFX:Clone()
SFX.Parent = char
--SFX:Play()
game.Debris:AddItem(SFX, 1)

end``` static hitfx

torn plaza
vocal walrus
#

5th, this nonsense repeated lua if WhatToFetch == "Debounce" then return M1Debounce[index] elseif WhatToFetch == "Number" then return M1Number[index] end

#

6th, this is overengineered for no good reason lua local char = StunnedCharacters[i] if i < #StunnedCharacters then local lastIndex = #StunnedCharacters local lastChar = StunnedCharacters[lastIndex] StunnedCharacters[i] = lastChar StunEndTime[i] = StunEndTime[lastIndex] stunIndexMap[lastChar] = i

torn plaza
vocal walrus
#

there's not really a good reason to have so many tables for this

#

just use one

#

combatData[char]={cooldowns={} etc

torn plaza
#

Cuz organized arrays are read easier than dictionaries due to dictionaries having scattered data

vocal walrus
#

your obsession with optimization here is misguided

#

it's a common problem, see it all the time

#

believe it or not, you cannot optimize past 60fps you dingus

torn plaza
vocal walrus
torn plaza
vocal walrus
#

adding to it is more difficult than it needs to be

#

local vfxpart = workspace:WaitForChild("VFXPart") lol

#

that's reason #7

#

reason #8 hardcoded speeds ```lua

local function resetHumanoidSetting(char)
local humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50

end

local function stunHumanoid(char)
local humanoid = char:FindFirstChild("Humanoid")
if not humanoid then return end
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
end

vocal walrus
vocal walrus
torn plaza
torn plaza
vocal walrus
#

the only positive thing i can really say about it is that it doesn't appear to be broken, aside from the memory leak

vocal walrus
#

task.delay(stunDuration, reviveHumanoid, hum) derp

torn plaza
vocal walrus
#

you do need it stacking though so you task.cancel(reviveHumanoidQueue[hum]) task.spawn(...) but that's still less work than doing all this stuff

vocal walrus
torn plaza
vocal walrus
#

i can tell you haven't worked on large projects before

torn plaza
#

I don’t have streaming enabled

vocal walrus
#

that's literally insane

#

mobile users gonna love your game

torn plaza
vocal walrus
# torn plaza

hahahahahaha yeah and what's funny is you throw it away at the first opportunity in 90% of the places you use it ```lua
function module.CheckBlock(char)
local index = blockIndexMap[char]
...
function module.EndBlock(char)
local index = blockIndexMap[char]
...
function module.StartBlock(char)
local index = blockIndexMap[char]
...
function module.CheckStun(char)
local index = stunIndexMap[char]
...
function module.Stun(char, StunTime)
local index = stunIndexMap[char]
...
function module.FetchM1Data(char, WhatToFetch)
local index = M1IndexMap[char]
...
function module.ChangeM1Info(char, change, changevalue)
local index = M1IndexMap[char]
...
function module.AddM1Character(char)
local index = M1IndexMap[char]

#

this is what premature optimization gets you

#

stop optimizing stuff that doesnt need it

#

but hey what do i know

vocal walrus
#

OpTiMiZaTiOn!

torn plaza
#

Bro did not answer the question SobPray

vocal walrus
#

let's do dumb things to optimize memory lookup but immediately thrown out all the work done with higher memory overhead, and then disable the one feature that makes roblox reliable on mobile. Why? Because some guy on reddit said it was mOrE oPtImIzEd

torn plaza
torn plaza
vocal walrus
#

you would need an exceptionally small game to justify turning off streaming

torn plaza
vocal walrus
#

just use a regular dict like a normal person

#

frankly you should be more concerned about the endpoints than microoptimizations like this. if, and only if, it becomes a bottleneck should come back to it and consider maybe reducing cpu usage

#

coz again, you cannot optimize past 60fps

#

the biggest problem with all this is the time it takes to develop this stuff with these added "optimizations" when your time could've been better spent making it more robust and do more things, or working on other aspects of your game

torn plaza
torn plaza
vocal walrus
# torn plaza It’s not a full game it’s just a combat system for practice so I’m tryna optimiz...

from experience most people who want this are making their own for the same reason you are. as far as selling it goes, no one is going to buy it unless it has a good reputation. here's 3 i found for free after 30 seconds of googling:
https://devforum.roblox.com/t/open-source-simple-combat-system-with-blocking-and-stun/2484521
https://devforum.roblox.com/t/simple-m1-combat-system/2560101
https://devforum.roblox.com/t/another-open-sourced-combat-system/2828863

that's before the thousands of tutorials on it, because every ipad kid wants their own tsb clone:
https://www.youtube.com/watch?v=AX3rWUj5gRo
https://www.youtube.com/watch?v=BkvVhIlPeL8
https://www.youtube.com/watch?v=lX4CF9CQTUA
https://www.youtube.com/watch?v=zZmuuRhdUgQ

vocal walrus
# vocal walrus the biggest problem with all this is the time it takes to develop this stuff wit...

the biggest take-away i hope you take from all this is precisely this. Optimize your time first. You could spend a week microoptimizing an unfinished part of your project only to come back later and re-do it all because your first technique wasn't good enough for the job. that is dev time and effort you could have better spent doing literally anything else. it may feel like you have infinite time but you don't.

torn plaza
vocal walrus
vocal walrus
torn plaza
vocal walrus
# torn plaza Extensive research

you'll extensively research people's opinions of a subject, but you won't research the subject itself?

Makes sense to me! 💃

vocal walrus
#

in case you haven't noticed, the priority with optimization is not actually optimal code performance; the priority is actually optimizing development time and effort, and understanding for yourself how and why one technique is better than another coz if you don't know which technique is better without someone telling you which one with a 'trust me bro' you don't know anything about optimizing.

torn plaza
#

Also can you answer my question

vocal walrus
#

i do understand that newbie and beginner devs place a lot of highlight and emphasis on performant code, but it's really overdone to an unnecessarily obsessive degree. this is the 20th centure, we're not in the 90's anymore where the best hardware you could expect was 3.5MHz, 128KB ram Super Nintendo. modern computers have multi-core cpu's in the range of GHz, and similar in the GB's of ram. It's okay to have some flawed code, the only goal is staying above 60fps.

torn plaza
#

You’re egdinnnng me bro 😭

vocal walrus
torn plaza
#

Anything but answer my question iphone_tired 💔 🙏 🥀 🎋 😢 SobPray

vocal walrus
torn plaza
vocal walrus
torn plaza
#

I guess I’ll take the path of optimization 😔 ✌️

vocal walrus
vocal walrus
#

when you do that properly, your second question is already answered in the same process Thumbs

torn plaza
vocal walrus
#

it has never been uncertain of anything either

torn plaza
vocal walrus
#

and there's no flaws or faults with relying on deepseek's advice whatsoever.

vocal walrus
torn plaza
#

I use it as a building block

#

Cuz scripters be gatekeeping advice fr

vocal walrus
#

i have not gatekept advice from you

vocal walrus
#

not that i had any obligation to share that advice with you in the first place, but i chose to do so anyway

#

for your benefit

torn plaza
vocal walrus
#

if i spoonfeed you my opinion on what i think you should do with your project is not going to help you at all tomorrow.

torn plaza
vocal walrus
#

and besides, why are you letting people tell you what to do wtf

torn plaza
vocal walrus
#

in my opinion what you should do with your combat system is transfer a million robux to me Thumbs

#

you see? hehe

vocal walrus
vocal walrus
torn plaza
vocal walrus
vocal walrus
torn plaza
vocal walrus
#

you're using dod pattern because some guy on reddit said it was optimized, was that your decision too, or are you just obediently doing as you're told?

torn plaza
#

That Reddit post was just a piece of the puzzle

vocal walrus
#

i suppose deciding to blindly follow other people's instructions and opinions is itself a decision

torn plaza
#

I’m tryna practice different paradigms anyways

vocal walrus
#

or, if not totally blind, it would be blindly following OpTiMiZaTiOn without regard for the impact on development processes. spending days, weeks optimizing something that never needed it in the first place instead of making things functional, robust, and stable. not a decision I would make, but you're free to make those decisions yourself fingerguns 'Murica! 🦅

vocal walrus
torn plaza
#

Just for reference yknow

vocal walrus
#

if i might suggest, in your practices, benchmark everything

torn plaza
vocal walrus
#

optimizations are merely a suggestion if you do not have benchmark stats to prove it

torn plaza
toxic jetty
toxic jetty
#

I didnt wanna say nun bout the issues with it

#

they only asked for optimizing

vocal walrus
# toxic jetty they only asked for optimizing

anything short of benchmarks is mere speculation and not worth anyone's time. in its place i suggest best practices instead of chasing the dragon of perfect performance; it is a fool's errand in the real world, there is no 0cpu method. But what do i know, i mean you can keep chasing the dragon and never release anything along the way if you really want to, idk i'm not your dad and you can make your own decisions 🤷

#

it's like, why doesn't everyone just simply switch to a dvorak keyboard? it's more efficient!
have fun researching why that sounds good on paper but doesn't work in the real world.

toxic jetty
#

or

#

sum thaty requires a lot of iterations

#

^ for roblox that is

toxic jetty
#

@torn plazaalso btw if u really care that much, using : is faster than using .

#
local q = {}

q.Name = "hi"

function q.GetName()
    local a = q.Name
end

function q:GetName2()
    local a = self.Name
end

local s = tick()

for i=1, 5e7 do
    q.GetName()
end

print(tick() - s)

s = tick()
for i=1,5e7 do
    q:GetName2()
end

print(tick() - s)
#

^ try it yourself

torn plaza
torn plaza
cedar badger
#

I prob read it wrong but that’s my still

vocal walrus
#

people have a hard time accepting that but it is true particularly for beginners

#

it's okay to make bad code

cedar badger
#

So should u like

#

Optimize everything once you’re done with it?

vocal walrus
#

yes optimize later if/when framerate is a problem

#

you cannot optimize past 60fps

cedar badger
#

cause when I’m scripting I’m always thinking of scenarios that could be more optimized or readable but I feel like I shouldn’t do it and save it for later

vocal walrus
#

yea just take note of the dumb stuff that you end up doing and improve that for next iteration

vocal walrus
#

iteration is key - you will never make it right the first time

cedar badger
#

This whole discussion was actually worth reading icl 😭

torn plaza
sly wraith
#

i js finished brawl dev's beginner series