Whats the best way for character datas

local WardenData = {
	
	

	["test"] = {
		AttackStartTime = 0.25,
		AttackDuration = 0.25,
		AttackMissedRecovery = 1,
		AttackRecovery = 1.5,
	}}
	

return WardenData

So basically i want to have individiual datas for characters into a place and acess it whenever i need to. is this the best way to do it? because it currently works but i kinda wanna also do type checking aswell so it feels more organised

im kinda bad at explaining this hopefully you get the point
an example would be like charactes in games where diffrent characters would have diffrent stats

1 Like

If you are referring to grabbing default stats for NPCs or stats for gear from a module script, then I would say that’s a good use of it. I’m actually currently doing this with a game I’m working on and it definitely helps me organize my code, cause I can just easily retrieve the data via → gameInfo["Bacon Burger"].Energy

As for checking the type of data it is, you can just use type() or typeof() after you retrieve it. However, I’m not exactly sure why you would need to do this because I would assume that you wouldn’t be changing the data type or even changing the data at all in the module script.
image

the type checking i mean like in the module script so i could autofill the data easily but thanks that gave me a better idea to do it

image
im not quite sure but im guessing arround this

You have to index a typo on a variable to make it even do “his work” this would do nothing…

Example:

local module = {}

--simple typo

type Test = {
	TestAttack: (() -> ())? | EnumItem? | boolean? | BodyForce?;
	TestDamage: number;
	TestName: string | number;
	TestSomething: (number, string) -> {any}
}

local TestVariable: Test = {
	TestAttack = true,
	TestDamage = 10,
	TestName = "Dog :skull:",
	TestSomething = function(a, b)
		return {a+tonumber(b)}
	end,
}

return module


thanks for the example im gonna try it

image
is this correct?
sorry im kinda dumb just wanted to double check

Yeah, it is totally right, you can organize your code with this, if you want a good typo in your game else you don’t have to as you feel it’s better for you, like that, though it’s perfect, so yeah all good.

1 Like

thanks 1 more question


^
a part of my other script code

how can i make it global like it gets the type
sorry bad explanation

like i could get the autofill and stuff on other scripts

You mean it can be seen in every script you require the module on? If so use export before the type.
Hope this helps!

yep

image


is it like this? i think i did something wrong its not giving the autofill

You first have to index the “AttackWardenData” with all the values.

sorry i dont kinda get what you mean could you give me an example

sorry i figured it out thanks alot your a lifesaver

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.