Posted: Wed Sep 15, 2021 2:23 pm Post subject: What is the best way to filter out a nil value.
This address I'm using to get a value from can sometimes give a nil value. I was trying to filter out the nil result. I wanted it to keep looping until it got a result that wasn't nil. But it still fails when doing the math.floor because it was trying to do math on a nil value.
Code:
while true do
if tonumber(DirectionFloatValue.Value) ~= nil then
ArrowMath = math.floor(tonumber(DirectionFloatValue.Value))
break
end
end
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
Posted: Wed Sep 15, 2021 2:54 pm Post subject: Re: What is the best way to filter out a nil value.
AmyGrrl wrote:
This address I'm using to get a value from can sometimes give a nil value. I was trying to filter out the nil result. I wanted it to keep looping until it got a result that wasn't nil. But it still fails when doing the math.floor because it was trying to do math on a nil value.
Code:
while true do
if tonumber(DirectionFloatValue.Value) ~= nil then
ArrowMath = math.floor(tonumber(DirectionFloatValue.Value))
break
end
end
perhaps the value becomes unreadable again right after one proper read
try
Code:
while true do
local v=tonumber(DirectionFloatValue.Value)
if v ~= nil then
ArrowMath = v
break
end
end
or better use a timer instead of while loop _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum