Redanite
(Redacool)
August 13, 2021, 2:01am
1
How would I achieve a math operation from a type object? I want to be able to boost the damage dependent on it’s dmgboost.
type CombatProperties = {
iframes: boolean,
damage: integer,
dmgboost: integer
}
--Properties
function combatSystem:Create(): CombatProperties
return {
iframes = false,
damage = 1,
dmgboost = 1
}
end
How would I multiply the damage by the dmgboost? This is a module script.
nkmisoup
(metaneko)
August 13, 2021, 2:09am
2
You’d have to set it after you called the function
Redanite
(Redacool)
August 13, 2021, 2:12am
3
Could I have an example? Doing something like
combatSystem.damage = combatSystem.damage * combatSystem.dmgboost
Would just throw an error.
nkmisoup
(metaneko)
August 13, 2021, 2:15am
4
What’s the error message in the output?
Redanite
(Redacool)
August 13, 2021, 2:16am
5
attempt to perform arithmetic (mul) on nil
As well as
Requested module experienced an error while loading
nkmisoup
(metaneko)
August 13, 2021, 2:18am
6
Do you have ‘integer’ defined as a type? It’s not an actual type in Roblox
nkmisoup
(metaneko)
August 13, 2021, 2:22am
7
And as a follow up, when I tried to recreate the code, it worked without any issues, assuming this was the correct setup for it.
--ModuleScript
local CombatSystem = {}
type CombatProperties = {
iframes: boolean,
damage: integer,
dmgboost: integer
}
function CombatSystem:Create() : CombatProperties
return {
iframes = false,
damage = 1,
dmgboost = 2
}
end
return CombatSystem
--Test script I used
local x = require(script.Parent);
local y = x:Create();
y.damage *= y.dmgboost;
Redanite
(Redacool)
August 13, 2021, 2:23am
8
I’m trying to make it work in a way in which if the dmgboost is something like 2, it multiples it by the damage throughout multiple scripts. I might be doing something incorrect here.
nkmisoup
(metaneko)
August 13, 2021, 2:24am
9
Can you show me the script that threw an error?
Redanite
(Redacool)
August 13, 2021, 2:24am
10
I figured out the problem, but nonetheless still have another problem with making it global
nkmisoup
(metaneko)
August 13, 2021, 2:27am
11
I’d just make another property called “baseDamage” or something like that to keep track of what it originally was.