|
| 02 Jul 2016 03:04 AM |
I asked about this earlier but i cant find the thread, but my question is how would I be able to tell the difference between a CFrame and a V3 value? I did the pcall method but that way is extremely laggy as Im checking multiple values every frame.
|
|
|
| Report Abuse |
|
|
topcst
|
  |
| Joined: 20 Dec 2011 |
| Total Posts: 3052 |
|
|
| 02 Jul 2016 03:06 AM |
| I personally would use CFrame, But theyre equal. |
|
|
| Report Abuse |
|
|
0Dan
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 2552 |
|
|
| 02 Jul 2016 03:10 AM |
I don't think there is a build in way to tell the difference, but if you really need to know then you can just use this:
--There really should be a better way to do this function CheckType(cv) local success, message = pcall(function() local a = cv.p end) return success end
if(CheckType(CFrame.new(1,1,1))==true)then print("Is CFrame") else print("Is Vector3") end
if(CheckType(Vector3.new(1,1,1))==true)then print("Is CFrame") else print("Is Vector3") end
local l={e={a={v={e=function()print("bye")end}}}} l.e.a.v.e() |
|
|
| Report Abuse |
|
|
0Dan
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 2552 |
|
|
| 02 Jul 2016 03:11 AM |
built in way*
local l={e={a={v={e=function()print("bye")end}}}} l.e.a.v.e() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:12 AM |
There is a built-in way, it's just unavailable to us.
OP what are you trying to do? Maybe you can keep track of what's being passed so you know the type beforehand. |
|
|
| Report Abuse |
|
|
0Dan
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 2552 |
|
|
| 02 Jul 2016 03:17 AM |
Even though I can really use it I'm still curious, what is the built in way? ;o
local l={e={a={v={e=function()print("bye")end}}}} l.e.a.v.e() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:19 AM |
if getmetatable(obj).__type == "Vector3" then
The metatable of all Roblox objects are locked, but internally they can access it if they want and I'm sure the types are registered in the Lua registry as well. |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:19 AM |
I have a set of CFrame and Vector3 values that need to be 'added' to each other in a specific order and i need a function to do it by itself but adding CFrame to a CFrame is different than adding a CFrame to a Vector3 and vice versa
Also Dan i already said I tried pcall and its too laggy to use
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:20 AM |
| Why not just have 2 different functions, one that deals with CF*CF and another that does CF+V3? |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:21 AM |
@cnt that returns nil no matter what
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:22 AM |
@cnt i cant have 2 functions because i cant differentiate the values (the values are stored inside of a table and can either be cframe or v3)
|
|
|
| Report Abuse |
|
|
0Dan
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 2552 |
|
|
| 02 Jul 2016 03:24 AM |
Just use my solution above
local l={e={a={v={e=function()print("bye")end}}}} l.e.a.v.e() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:25 AM |
"I did the pcall method but that way is extremely laggy as Im checking multiple values every frame."
|
|
|
| Report Abuse |
|
|
0Dan
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 2552 |
|
|
| 02 Jul 2016 03:27 AM |
If you're checking multiple values per frame would it not lag no matter how you do it?
local l={e={a={v={e=function()print("bye")end}}}} l.e.a.v.e() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:27 AM |
"@cnt i cant have 2 functions because i cant differentiate the values (the values are stored inside of a table and can either be cframe or v3)" How are you storing them? When you store them in the table why not just store their type as well? |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:28 AM |
No, i removed the pcall part and the script performance lowered by 7%
|
|
|
| Report Abuse |
|
|
0Dan
|
  |
| Joined: 22 Oct 2009 |
| Total Posts: 2552 |
|
|
| 02 Jul 2016 03:33 AM |
Using pcall made your script performance go up by 7%? Are you looping without any waits?
local l={e={a={v={e=function()print("bye")end}}}} l.e.a.v.e() |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:35 AM |
@cnt I did what you said and it can tell which values are which, but its erroring with this kind of example;
CF + V3 + V3 * CF * CF * CF --the last CF causes the error
attempt to multiply a Vector3 with an incompatible value type or nil
the value type isnt nil either, its a CF
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:36 AM |
Of course it's going to be much less efficient, he said he was doing it a bunch of times per frame (meaning at least 120 times a second?) and you're creating functions that many times as well.
Here's a better version that uses pcall:
local components = CFrame.new().components local function isCFrame(val) return pcall(components, val) == true end |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:36 AM |
Okay this error is my fault, i set a value thats considered as a CFrame to a Vector3
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 03:37 AM |
"CF + V3 + V3 * CF * CF * CF --the last CF causes the error"
Because V3 * CF is not a defined operation. Is (CF + V3 + V3) * CF * CF * CF what you wanted? |
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 04:22 AM |
I fixed the problem, thx cnt
|
|
|
| Report Abuse |
|
|