#Some logic error thats pmo

1 messages · Page 1 of 1 (latest)

hardy coyote
#

The two images are the only things im using. As you can see i have recursion in the burn script and yes ik it will crash my game but it ment to convey what im trying to do.

I want to turn off the state before adding a new one. Reason for this is it will give the illusion that the time for burn is resetting. And It turns off old burn because the while loop checks if the burn state is still even a thing, and if it not it breaks.

So yeah

hardy coyote
#

@silent surge

hardy coyote
#

wdym

silent surge
#

z

iron gorge
#

like get rid of the string

#

just do the table

hardy coyote
#

y

silent surge
#

lemme read

iron gorge
#

and it'll be indexed at 1

#

why do Tier 1

silent surge
#

yea

iron gorge
#

Tier 2

hardy coyote
#

because

iron gorge
#

Tier 3

#

its dumb

hardy coyote
#

BECAUSE

#

it looks cool

#

and doesnt matter

silent surge
#

it will be hardcoded as fuck

iron gorge
silent surge
hardy coyote
#

I DIDNT ASK FOR OPTIMISAIOTNS crying

iron gorge
#

also ur casing is shit

#

what else can i shit on

hardy coyote
#

wdym

iron gorge
#

its not that hard to make a variable

hardy coyote
#

my casing is fine

iron gorge
#

no its not bro 😭

silent surge
#

bro

hardy coyote
#

im not making it a constant or pascal case or whatever

silent surge
#

ur casing is

#

really bad.

hardy coyote
#

if i can read it, its fine

#

ill only care when im on a team

silent surge
#

u can just use somethingl ike this

hardy coyote
#

can we get to the actual point

silent surge
#

local bool, bool1 = true, false

iron gorge
#

also these long spaces are pmo

silent surge
#

ong

hardy coyote
iron gorge
hardy coyote
#

no

iron gorge
#

then get rid of them

hardy coyote
#

no

silent surge
#

can u read this

hardy coyote
#

yes but it makes it look messy imo

silent surge
#

nah

#

it doesnt

iron gorge
#

im asking u to get rid of the long ones

#

not the 1 line ones

hardy coyote
#

i said imo

hardy coyote
#

idk

silent surge
#

@iron gorge

#

bro

hardy coyote
#

they just there i forget to remove them

silent surge
#

how can i erase hardcoded stuff

#

example

#

dis a bit hardcoded

#

is it

iron gorge
#

oh i just do typeof(module) for the functions

#

and then u can do & {}

silent surge
#

i use export type

#

cuz well

#

im learning types

silent surge
iron gorge
#

no i mean like this

silent surge
hardy coyote
#

whats ::

iron gorge
#

export as this type

#

basically

silent surge
#

yea

hardy coyote
#

this is what i ment for in depth scripting, no one ever shows me ts

silent surge
#

should i use typeof?

#

i should

iron gorge
#

yes

dense mulch
#

does a good morning hello become hi?

#

because

#

if task.wait

#

then

#

workspace:GetParent():GetParent():GetParent()

silent surge
hardy coyote
#

logic error

#

@silent surge

#

gng

silent surge
#

what does gng mean

hardy coyote
#

@ivory flame i know you read scripting help a lot so js asking if u could

#

appreciate it

silent surge
#

dont ping my man pyro

#

hes busy

hardy coyote
#

like what do u want me to do

#

😢

silent surge
#

uh

#

idk

velvet plank
#

Boiii

ivory flame
# silent surge

Amateur line compression lua Advance=function(self:BufferIStream_C,v:number) self.Cursor+=v if self.Cursor>buffer.len(self.Nug) then self:Flush() end end; writestring1=function(self:BufferIStream_C,v:string) local len=string.len(v) self:Alloc(len+1) buffer.writeu8(self.Nug,self.Cursor,len) buffer.writestring(self.Nug,self.Cursor+1,v) self.Cursor+=1+len end; writestring2=function(self:BufferIStream_C,v:string) local len=string.len(v) self:Alloc(len+2) buffer.writeu16(self.Nug,self.Cursor,len) buffer.writestring(self.Nug,self.Cursor+2,v) self.Cursor+=2+len end; Flush=function(self:BufferIStream_C,len:number?) local nugbuf=buffer.create(self.Cursor) buffer.copy(nugbuf,0,self.Nug,0,self.Cursor) table.insert(self.Nuggets,nugbuf) self.Nug=buffer.create(len or NUGGET_SIZE) self.TotalSize+=self.Cursor self.Cursor=0 end; writebuffer8=function(self:BufferIStream_C,v:buffer) self:Alloc(buffer.len(v)) buffer.copy(self.Nug,self.Cursor,v) self.Cursor+=buffer.len(v) end;

ivory flame
#

to fix it you need to make your abstraction better, i'd suggest adding some kind of State.OnTick method that is auto connected/disconnected with the state, this way you can have that while true loop running and you never have to actually disconnect it, instead you can just update its state and it will continue ticking with new values.

hardy coyote
#

instead of resetting i refresh it

hardy coyote
#

still dk how this code works tho lol

ivory flame
hardy coyote
#

dk why he js gave me it

hardy coyote
#

idk its not how i write code

#

so i dont understand most of it

#

the comments just say whats happening

ivory flame
hardy coyote
#

s3

ivory flame
#

why would immortalwhite just give you working code

hardy coyote
#

but it would be nice

#

to learn what is even happening

#

instead of being thrown code

#

he said read it and understand it later or something

ivory flame
#

thats very strange but the bottom line here is really simple

#

don't use code you don't understand.

hardy coyote
#

what if its like 10k lines of code

#

for shiftlock

ivory flame
#

if you cannot follow along what this structure is doing you don't deserve to use it.

#

you haven't earned it

hardy coyote
ivory flame
#

it's like teaching someone to drive in a lambo, its just stupid, dont do that

hardy coyote
#

we look if the player is already burning in active burns, and then we set the expiry and dps in that already made burn index to whatever the new value is

if not we js create a new one

#

but then

#

how the hell does last part work

#

if this is the second time we do it

ivory flame
#

yeah you haven't earned these patterns yet

hardy coyote
#

wouldnt there be two while loops going on?

#

since we never remove the old one

hardy coyote
#

idk why

ivory flame
#

so dont use it

hardy coyote
#

he gave

#

i'd rather write up my own

hardy coyote
#

ill write up my own

#

but uhm

#

could you point me in the right direction for the last part

#

whats going on there?

#

i'd like to know

ivory flame
# hardy coyote how the hell does last part work

but on the side, to answer this, that's the responsibility of the states handler not the state itself. the state handler creates connection to heartbeat or some other kind of repeating loop that calls a function in the specific state. when you update the values in the state you don't recreate the loop - instead the loop is written dumb and as a slave to the values: it doesn't decide anything, it just takes the current values and does the work with that. at most it might decide if the state should remove itself, but that's it.

hardy coyote
#

im gonna sound so annoying but

#

what heartbeat connection?

#

oh wait

#

the while loop you mean

#

yeah alr

ivory flame
hardy coyote
#

heartbeat:wait()

#

or something , i dont remember exactly

ivory flame
#

it's all the same stuff

hardy coyote
#

why is it written dumb as a slave

ivory flame
#

if you design your code right you can let the state yield its own tick thread

hardy coyote
#

why does it not create two? i dont see where we overwrite it

ivory flame
#

so you can wait arbitrary length

ivory flame
ivory flame
# hardy coyote

how you have it now you have all this burn = { dps} and task.spawn and if not StateCanValidlyApply then return end (in the form of if not hum or dps<1 or duration<1 then return end) this does not need to be in the application of the state, it should be a different function on its own because what else you gonna do at that point? chr:SetAttribute("Burning",true) oh wait sorry i changed my mind immediately chr:SetAttribute("Burning",false)

#

why do that dumb thing when instead

#

function onBurnTick() local dps=self.BurnData.dps self.StateHost.Humanoid:TakeDamage(dps) end

#

like

ivory flame
#

writing functions the way you do, where everything is extremely linear, is a really bad style

#

over-using the while true do loops to create repeating code, and then using this for everything that repeats, completely ignoring event based paradigms, is where you're getting screwed over, and will continue getting screwed over up until you get rid of those training wheels. while true do is for first-day scripters. time to break the bad habit.

#

instead what you need is to figure out some code as to how to write a better version of those while true do loops, where you can have 3 functions: one to start the loop, one to "step" the loop (each iteration), and one to stop the loop, all independent of each other.

#

when you figure that out, you will understand how to fix this.

hardy coyote
#

recursion?

ivory flame
#

no

#

don't throw dumb word salad around it isnt helpful

hardy coyote
#

no cus you said

ivory flame
hardy coyote
#

oh

#

loop my bad

hardy coyote
ivory flame
#

the start/stop/step pattern is very common for timers that have variable duration

hardy coyote
#

but if you say while true do is for low level scripters, then what else do i use for a loop that yields

ivory flame
#

coz with start/stop/step, you can then insert in an update function that changes the delay until the next step, or does other things to interrupt the loop

#

it's the same mistake that humanoid.MoveToFinished:Wait() is.

#

you cannot interrupt it if you do that

#

so instead you need to make interruptable code, aka event based paradigm

ivory flame
#

i can assure you it will be the weirdest while true do loop you've ever written.

hardy coyote
#

one function starts the loop, the other ends it and one is the function that i feed into the loop, or is step the one that controls well, the stepping

ivory flame
#

once you got that under your belt you should be good to go for the rest of this

ivory flame
#

but the basics of it is start/stop/step

#

step is where the actual work usually happens like damage is dealt

hardy coyote
#

yeah

#

thats what i meant

ivory flame
#

start/stop are kind-of like interruptions, you can easily add more of them to control stepper in unique ways

hardy coyote
#

And this is a loop, not a recursive function right

ivory flame
#

you've confused recursion with something else

#

do not use recursion for this pattern

#

it is just a regular while true do loop, but instead of being impossible to interrupt, you've added the functions to start and stop it

#

that step is one that beginners usually can't make

#

they get stuck in their love for while true do and never find out what you can really do when you take the training wheels off.

hardy coyote
#

im assuming once i get this down it will fit neatly into my state system

ivory flame
#

they're not trivial to write

ivory flame
#

like set your current project aside for a moment and just write up a very simple proof of concept

#

are you even able to make a while true do loop that can be stopped and started at will? - maybe add in ability to pause it too instead of outright stopping?

#

it's the same as doing task.delay(time, func) and then changing the delay later on

#

it's a bit awkward to do but it's very powerful pattern

hardy coyote
#

1 sec

hardy coyote
ivory flame
#

its very similar to while true do if break_condition then break end dostuff() end but you get more control over it

hardy coyote
#

i did coroutines

#

oh my days

#

im so sorry

#

im act wasting your time, arent i

ivory flame
#
local ticker
local dmg
local LoopDelay=0
function OnStep()
  print("stepped with damage:",dmg)
end
function Looper()
  while true do
    OnStep()
    task.wait(LoopDelay)
  end
end
function StartAdjustLoop(delay,dmgValue)
  dmg=dmgValue
  if ticker then task.cancel(ticker) end
  LoopDelay=delay
  ticker=task.delay(delay,Looper)
end
function Stop()
  if ticker then ticker=task.cancel(ticker) end
end``` this is a very beginner basic one using a timed delay instead of every tick
#

you could make stop set a break condition too

#

similar outcome

#

the heartbeat one is much nicer though but only relevant if you need it stepping every tick

#
local ticker
local dmg
function StopLoop()
  if ticker then ticker=ticker:Disconnect() end
end
function OnStep()
  print("stepped with damage:",dmg)
  if math.random(1,100)==1 then StopLoop() end
end
function StartLoop(dmgValue)
  dmg=dmgValue
  if not ticker then ticker=RunService.Heartbeat:Connect(OnStep) end
end
hardy coyote
#

i dont think ill need a delay

#

so task.spawn is fine

hardy coyote
ivory flame
hardy coyote
#

i dont know why i didnt understand

hardy coyote
ivory flame
#

don't

hardy coyote
#

i can yield the while, but not the runservice

ivory flame
#

bother

#

with performance

#

of things

#

you don't understand

hardy coyote
#

uhhhhhhhhhhhhhhhhhhhhh

#

okay

#

alr i understand it now

#

i should probally experiment with it

ivory flame
hardy coyote
ivory flame
#

you really shouldn't rely on chatgpt for stuff like this

hardy coyote
#

?

#

???

#

i didnt use chatgpt...

#

i searched up stuff and i thought that coroutines do some of the stuff for me anyways

#

does it look chatgpt?

#

wow im bad

ivory flame
#
local ticker
local dmg
function OnStep()
  print("stepped with damage:",dmg)
end

function Looper()
  while true do
    OnStep()
    task.wait(1)
  end
end

function Start(dmgValue)
  dmg=dmgValue
  if not ticker then ticker=task.spawn(Looper) end
end

function Stop()
  pcall(task.cancel,ticker)
end``` would be one way to write the coroutine one, but usually with these you should refer to the first one for adjustable wait timer (you can make the next step run sooner if you needed to, whereas with this code you cannot do that)
ivory flame
# hardy coyote

this on the other hand is ai slop, that's not how you use coroutine.yield

hardy coyote
#

i just assumed thats how .yield works

#

if i used ai it would have turned out much better

ivory flame
ivory flame
#

Suspends the execution of the calling coroutine. Any arguments to yield are passed as extra results to resume.

#

if you want to use a version that uses coroutine.resume then you need much longer context and i think i wrote enough examples of these

hardy coyote
#

no no

#

i dont wanna bother myself with coroutines

ivory flame
#

in other words, you wouldn't use coroutine.resume for a timer unless you made your own scheduler

hardy coyote
#

aight let me try this again

ivory flame
#

anyway that should be enough for you to shake up how you've been writing these

hardy coyote
ivory flame
#

i also offer private tutoring at charge so if you need more and have robux for it lmk

ivory flame
#

its better to learn the pattern than to just dump it into one structure

#

because there's lots of different ways to write these and how you write it will change depending on context, a generalized module is not trivial. this is more like a basic concept than something you'd turn into a utility, but you can definitely make utilities out of it.

hardy coyote
#

yeah i get it

#

thanks pyro

silent surge
#

can i ask something early? @ivory flame are the codes i sent here s1?

#

sorry for pinging if ur busy

#

wait

#

i found out what line compression meant

#

okay true