it is saying: attempt to index nil With ‘Y’.
because i only said defoned the datatype and not the thing itself
but what i can do? i want it to print “MyType”
what should i define it as?
type MyType = {
Y: number,
X: number,
YD: number,
XD: number,
}
local MyType = {}
function MyType.new(Y,X,YD,XD): MyType
local New: MyType
New = New
New.Y = Y
New.X = X
New.YD = YD
New.XD = X
return New
end
local d = MyType.new(1,3,4,5)
print(typeof(d))
1 Like
You are not able to change the value of typeof
afaik, it will always be table for tables.
You are also assigning New
to New
which is nil
, you should assign it to a table instead.
Question: will it return a table when i use typeof?
It will return the string "table"
as MyType.new() returns a table
no. did not work. the output said “table”.
@Luka_Gaming07
Mystxry12
(Mystxry)
March 12, 2022, 9:22am
#6
function MyType.new(Y,X,YD,XD): MyType
local New : MyType = {}
New.Y = Y
New.X = X
New.YD = YD
New.XD = X
return New
end
This is what you shud do. The typechecking was a little bit off.
no. that did not work; it even gave me a warning
RatiusRat
(Boopmaster)
March 12, 2022, 9:54am
#8
Are you trying to create a class like vector3?
i just wanted to test how creating a custom type works.
But yeah, Vector2,Vector3, Udim,Udim2
RatiusRat
(Boopmaster)
March 12, 2022, 10:34am
#10
Pretty sure those datatypes are just classes(built in by roblox)
hmmmm so you can’t actually just make it so that when you call:
typeof(idk anything) – returns custom type?
if it was true, then wouldnt be
table.concat the only existing solution or the way out of the problem?
RatiusRat
(Boopmaster)
March 12, 2022, 10:45am
#13
I think typeof is roblox’s custom function for datatypes including its built in ones. So I don’t think it would detect your custom datatypes.
Mystxry12
(Mystxry)
March 12, 2022, 10:56am
#14
K i just realized that ur variable overshadowing, i.e u r declaring MyType as a type
and as a table
. So it might automatically set the type as a table
.
that did not help att all.
Vector3.
Udim2
Y, X, YScale …
RatiusRat
(Boopmaster)
March 12, 2022, 6:51pm
#17
I don’t understand what you’re saying?
can you tell me something else cause…
MyType i dont think it will be a table or
imagine doing
type MyType = (Y:number,X:Nmber --.. and so on
RatiusRat
(Boopmaster)
March 12, 2022, 9:06pm
#19
It has to be a table ??? Vector3 and Udmi2 are classes that have functions that return a table. You the .new function using () and pass arguments.
that is not what i mean.
if you do:
typeof(Vector3)
returns Vector3 and NOT “table”
also, one more thing…
if i had to do what you’re saying then the output will return:
[“Y”] = 1,
And so on…
but i want to say insteaad : 1,3,4,5