#Error trying to call function in table

12 messages · Page 1 of 1 (latest)

rigid nacelle
#

I have an ability base class, and a child ability class, base class has default variables and a function. Child changes the value of those, i try to pass this as an argument in a function but its giving me an error

#

This is the function:

type AbilityType = typeof(AbilityClass.new())

local function onAbilityEvent(player, mousePos, a: AbilityType)
    a:UseAbility(player)
end
#

base class:

local Ability = {}

function Ability.new()
    local ReturningData = {}
    ReturningData.Name = "AbilityBase"
    ReturningData.Damage = 50
    ReturningData.Cooldown = 2.5
    function ReturningData:UseAbility(player)
        print("Ability used ", ReturningData.Name, " by ", player)
    end

    return ReturningData
end

return Ability
#

when i try to run the function it tells me an error "Attempt to call missing method 'UseAbility' of table"

safe hatchBOT
#

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

rigid nacelle
#

Error trying to call function in table

regal aurora
#

Remove the function definition from the scope of your constructor?

#

(I've never worked with Lua classes in my life)

#

Oh wait.. I think I see what you're trying to do...

#

No wait. I have no clue lmfao

rigid nacelle
#

subclass if it helps:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AbilityClass = require(ReplicatedStorage.AbilityType)

local A = AbilityClass.new()

A.Name = "Blah Blah"
A.Cooldown = 2
A.Damage = 50
function A:UseAbility(player)
    print(player)
end

return A
vivid crystal
#

hi sir