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

I saw a script from devforum and I don't understand it?

Asked by
Neon_N 104
4 years ago
Edited 4 years ago

link for script

local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

if withinScreenBounds then
   -- We have successfully detected if the player can see the part.
end

okay so you make two variables : _ and withinScreenBounds. But why do you need _ if you only use withinScreenBounds?

3 answers

Log in to vote
2
Answered by 4 years ago

The method used in the code :WorldToScreenPoint() returns a tuple in this case, essentially in the devforum code the developer wanted to store the tuple's return information in 2 variables having the first one as "underscore" ( _ ) because he/she doesn't want to really use it and marks it as irrelevant by naming it that way.

But essentially the method first returns a Vector3 for X and Y positions in the screen and a Z factor for depth and the second value returned from the method is just a bool that indicates if the point is within the screen, more information here:

https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint

Ad
Log in to vote
1
Answered by
pwx 1581 Moderation Voter
4 years ago

Normally some scripters do this incase you need to add another variable later depending on what you are trying to script, of course they can easily remove it afterwards if it is not needed. The script would work just as well as if it didn't have the second variable.

Log in to vote
-1
Answered by
gloveshun 119
4 years ago

i dont understand what are you want to know

Answer this question