#OOP design question for my combat game involving TIMERS

74 messages · Page 1 of 1 (latest)

dusk pulsar
#

I have this code

local Agent = {}
Agent.__index = Agent

function Agent.new(plr,meleeAnimations)
    
    local newAgent = {}
    setmetatable(newAgent,Agent)
    
    newAgent.player = plr
    newAgent.meleeAnimation = meleeAnimations -- this is supposed to be an array IN CHRONOLOGICAL ORDER OF HOW THE ANIMATIONS ARE RAN
    newAgent.canMove = true
    newAgent.canUseAbility = true
    
    
    return newAgent
end

-- metamethods, "they're so... meta"

return Agent

I want the booleans listed like canmove and canuseability have a timer that can be activated at anytime. This timer would change the booleans from true to false and at the end of the timer false to true. Normally this wouldn't be an issue however I want to allow this "Timer" to be spam able but I don't know how I would achieve this

#

Also I understand how this could be a super specific and redundant question.

#

Also my original solution was really haxy and very inefficient

edgy glacier
#

Can you repeat in simplier teerms

dusk pulsar
#

yeah

#

so

#

basically

#

you see those 2 booleans?

edgy glacier
#

Ye

dusk pulsar
#

I want them to have a property that turns them to false on a timer

#

and then back to true when the timer is finished

edgy glacier
#

So when the timer runs the boolean os set to false

dusk pulsar
#

no it's set to true

#

during the timer its false

#

Hey

#

actually have an idea

edgy glacier
#

So

wheat hullBOT
#

studio** You are now Level 5! **studio

edgy glacier
#

There Is a metamethod called __call

#

You could make It so when table gets called, It enables a timer with parameter the boolean you want to cjangey

#

Change

dusk pulsar
#

really?

#

that's a weird oddly convenient method

#

what happens when spammed

#

like if i used it multiple times

edgy glacier
#

Dependa like

#

How many times

umbral estuary
#

Or are you just referring to a boolean?

dusk pulsar
#

i don't want it to break it

umbral estuary
#

You can just make a thread (coroutine/task.spawn), then every time you try to call it just make if first check if it exists

umbral estuary
#

Then you can keep calling it, but it will only create the timer once

dusk pulsar
#

originally

dusk pulsar
#

once a new one is created

umbral estuary
#

Ah, so increase it (set it back to the full time e.g. 30 seconds)

dusk pulsar
wheat hullBOT
#

studio** You are now Level 3! **studio

dusk pulsar
#

it sounds complicated when i explain it

#

ok

umbral estuary
#

so what I think you currently mean is this:

timer 1 takes 30 seconds, timer 2 takes X seconds, timer 3 takes 60 seconds

timer 1: activated 25 seconds left -> called again -> set back to original 30 seconds, counting down again

timer 2: not activated, not doing shit

timer 3: activated, 35 seconds left -> called again -> set back to original 60 seconds, counting down again

dusk pulsar
#

wait

#

can you go into vc

#

so i can explain it more fluidly

umbral estuary
#

no, let's me be frank. I'm already reading other threads as well

#

If you cannot explain your issue then I can simply not help

dusk pulsar
#

oh ok mb

#

ok

#

I will right something to explain it alot better

#

So when we want the player to be unable to move for a certain time
we will use a method called agent:StartTimer(time, property : "in this case it will be the canMove property")

This function sets the canmove to false and then once the time reaches 0 it sets it back to false.

the issue is if you called the startTimer during another starttimer it would interfere with eachother.

umbral estuary
dusk pulsar
#

running both timers simultaneously

#

that's the issue

#

also the "agent" is just an object

#

just a substitute for the name PlayerData

umbral estuary
#

Oh wait, I forgot the name for "actors" and figured you were using them

wispy scarab
#

@umbral estuary can i dm u for help after ure done helping him plz?

umbral estuary
wheat hullBOT
#

studio** You are now Level 1! **studio

wispy scarab
#

qunem berant

#

ok

dusk pulsar
#

do you think i could store the coroutines in a table???

umbral estuary
#

You can

dusk pulsar
#

and append a new timer for every one that's created

#

and then automatically remove the earliest timers