Make Params Work With Nil Values

:green_circle: I will keep it simple, it is really useful that these RaycastParams and OverlapParams accept nested tables.

:red_circle: But there is still a minor issue, which is when there are nil values in between the tables it throws the error: “Unable to cast value to Object”.

Hypothetical Example:

local Table = {ObjectToIgnore, IgnoreList, Player.Character, Humanoid.SeatPart, AnotherIgnoreTable}


:large_blue_circle: Currently to fix this issue I just re-organize the table, but it would be better if Roblox’s could just skip the nil values in the tables because it happens often when you are inserting things into a table and some of those values end up being nil.

Thank you.


Unrelated But This Is Something I Dislike:

As much as I believe nil to refer to a non-existing value, it has effects on specific functions when you send it, is a behavior I never liked but it is what it is…

The problem is these APIs expect a full array, but you’re passing a sparse table, which is a mixture of an array and a hash-map.

Essentially {"A", nil, "C"} is just

{
	"A"
	[2] = nil,
	[3] = "C"
}

where the array part only contains "A", and the rest is in a dictionary. This is an optimization.


Because nil is different than passing nothing.

select("#", nil) -- 1
select("#") -- 0

Not happening. Too much potential for weird semantics with tables containing a lot of gaps.

If you’re worried about perf of constructing a variably sized Lua table you can always use if x then raycastParams:AddToFilter(x) if you weren’t aware of that method.

Thank you for the response! I will keep doing it then the way I am doing it, the reason for it was because a lot of time directly, I assign FilterDescendantsInstances a table right away containing values that can be nil, like calling a function that could return nil inside the table, leaving a hole. This means I need to do if statements and properly add them using AddToFilter instead.


I made this request, because I thought some filtering was being done every time the FilterDescendantsInstances property was changed by the developer. As we can see in this image:


But of course, the way I imagine it in Luau probably doesn’t happen on the other side of the spectrum…

There is some magic being done to flatten the table.

However that magic is much easier to do. Things are easy for the reflection system as long as it’s clear whether things are arrays or maps. Once you have a table with gaps in it, how things should be interpreted gets much more murky.

1 Like

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