alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:20 PM |
I'm trying to make a script to trigger an event when these two bricks are less than 1 stud from each other and this doesn't seem to be working :/
if (Part1 - Part2).magnitude <1 then game.Workspace.Part1.Transparency = 1 end |
|
|
| Report Abuse |
|
|
|
| 10 Jul 2011 02:35 PM |
What are Part1 and Part2? Vector3s? Bricks? Names?
(Part1.Position - Part2.Position).magnitude |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:37 PM |
| Part1 and Part2 are brick names. |
|
|
| Report Abuse |
|
|
|
| 10 Jul 2011 02:38 PM |
| (workspace.Part1.Position - workspace.Part2.Position).magnitude |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 10 Jul 2011 02:39 PM |
Are they in a model?
DrAgon fixed it, if so. |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:39 PM |
| Or before the script I could put Part1 = game.Workspace.Part1 right? |
|
|
| Report Abuse |
|
|
| |
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:42 PM |
| do I need to put "local" before the variable? |
|
|
| Report Abuse |
|
|
|
| 10 Jul 2011 02:46 PM |
| You don't need to, but you can |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:46 PM |
| I'm not really sure, but can you explain "local" to me real quick? |
|
|
| Report Abuse |
|
|
|
| 10 Jul 2011 02:48 PM |
I gave a short explanation to JINXY today. Here's what I said:
Making it local adds it to the local scope, which is faster in most cases. You're a beginner, so I don't think you should worry about scopes too much right now.
--This is a scope local a = 1 function bob() --Inside a function is a new scope local a = 2 --This a is 2 inside this scope print("Bob scope: " ..a) end bob() --But it is still 1 inside this scope print("Regular scope: "..a |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:49 PM |
| I've heard local script have no lag, would putting "local" before my variable cause it to have no lag? |
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
|
| 10 Jul 2011 02:50 PM |
"'print("Regular scope: "..a '
Nope.avi :P"
Oops. I copied it from an earlier post of mine and left off the end character. :P |
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 02:54 PM |
| meh. I don't get it, but I guess I've gotta learn sometime :P |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 03:09 PM |
grrr, I altered the script some and now it doesn't work >.>
if (workspace.Elevator.Position - workspace.Detector.position).magnitude<1 then game.Workspace.Glower.Reflectance = 0.5 end
|
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 10 Jul 2011 03:14 PM |
if (workspace.Elevator.Position - workspace.Detector.Position).magnitude<1 then game.Workspace.Glower.Reflectance = 0.5 end
Forgot a capital on the other "Position" |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 03:17 PM |
| Ahhhh, thanks. I forget about that sometimes :P |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 03:22 PM |
| This is stupid..... When the the bodyposition changes to where its closer than 1 to the Detector, it doesnt glow. But if I save it that way, then come back, the brick is glowing. Why does it not work instantly? |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 10 Jul 2011 03:24 PM |
With magnitude you always need to use a loop.
while wait() do if (workspace.Elevator.Position - workspace.Detector.Position).magnitude<1 then game.Workspace.Glower.Reflectance = 0.5 end end |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 03:25 PM |
| Thanks, I thought it needed to check every so often, but wasn't sure :P. Thanks again. |
|
|
| Report Abuse |
|
|
myrco919
|
  |
| Joined: 12 Jun 2009 |
| Total Posts: 13241 |
|
| |
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 03:28 PM |
Um, when I move the brick out of 1 stud within the brick, the bricks transparency doesnt go back to 0. Do I need to put something like
while wait() do if (Workspace.Elevator.Position - Workspace.Detector.Position).magnitude < 1 then game.Workspace.Glower.Reflectance = 0.5 if (Workspace.Elevator.Position - Workspace.Detector.Position).magnitude>1 then game.Workspace.Glower.Reflectance = 0 end end end
? |
|
|
| Report Abuse |
|
|
alanze
|
  |
| Joined: 05 Jul 2008 |
| Total Posts: 1288 |
|
|
| 10 Jul 2011 03:32 PM |
while wait() do if (Workspace.Elevator.Position - Workspace.Detector.Position).magnitude < 1 then game.Workspace.Glower.Reflectance = 0.5 while wait() do if (Workspace.Elevator.Position - Workspace.Detector.Position).magnitude>1 then game.Workspace.Glower.Reflectance = 0 end end end end
Never mind I got it :D
|
|
|
| Report Abuse |
|
|