Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

if print(type(print)) prints a function shouldn't print(type(print('Noob'))) print a string?

Asked by 4 years ago
Edited 4 years ago

Theres no actual use of this if any one is gonna ask what im gonna use it on but

I noticed that doing

print(type(print)) -- Prints a function


print(type(print('ADHD'))) -- Errors

--Shouldn't it print string

I also had another problem

local Table = {}

if type(Table) == table then

end

-- It wont be equal 

--so I had to do 


if type(Table) == 'table' then

end

-- A string works but a function dosen't work?

1 answer

Log in to vote
1
Answered by 4 years ago

The "type" function returns a string of the type of argument you put in it.

print(type(print))

In this first one you are passing in just the function, so it will return "function", however in this one:

print(type(print('ADHD'))

You are now calling the function print, which does not return any value, so you end up trying to get the type of literally nothing, it isn't nil but it's the same as just not putting a value in there in the first place.

On to your next problem with tables

local Table = {}

if type(Table) == "table" then
    --//Code if the table is indeed a table
end

Due to the nature of the "type" function, it returns a string of the type of argument you put inside of it. So since we pass in a table here, the response will be a string that reads "table".

Just like these two examples, there are more items you can get the type of ranging from numbers to strings to userdata and booleans. You can learn more about the "type" function here. Good luck!

Ad

Answer this question