killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 09:09 PM |
| For example, the changed event. How would they make it detect when a value in the object is changed? Surely not a while true do, that would be very inefficient. |
|
|
| Report Abuse |
|
|
|
| 26 Jul 2012 09:12 PM |
| Well its written in C++ so its not lua slang :p im guessing its a type of loop that detects all the properties and tells the program when one changes :D |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 09:14 PM |
| That's so inefficient though... What about .touched event? |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jul 2012 09:18 PM |
The .Touched would be trigged by the collision detection.
The .Changed would probably be something a bit like metatables in Lua, or C# properties (though I don't know how this would work in C++, but in C# it's:
public string Name { public get; public set { this = value; callChangedEvent(); } };
I think... I'm better at java) |
|
|
| Report Abuse |
|
|
|
| 26 Jul 2012 09:18 PM |
.touched would proably be a raycast of when something is either at
x<_0 distance
which is 0 or closer since characters sag into things because of gravity :p |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 09:25 PM |
@post above post above me You realize you said Touched triggered by collision detection right? *Claps* And you used a changed thing in your C example, but what I want to know is HOW they make those. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 26 Jul 2012 09:27 PM |
Well yes, of course it's triggered by collision detection. They could maybe check if the parts involved have a touched event, if so then they call it and pass the other part as an arguement.
The example I used was in C#, and I think it's done very differently in C++, I was just showing an example of how C# has properties that when you try to set them, you can do more than just set them, such as calling the Changed event. |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 09:36 PM |
| I don't think you understand the point of this thread, I'm asking HOW they make a "collision detection" or HOW they make the changed event "such as calling the Changed event" |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 26 Jul 2012 10:10 PM |
The answer is: We don't know, it's part of the C++ section of Roblox's program. It's CERTAINLY not a loop.
When Lua encounters a statement like
Part.Transparency = 1
What it is actually doing is calling a C++ function of the C++ Part class, the result of this function is to change the Transparency of the Part to 1. During that function, another function called NotifyChanged() is called.
class Part : public BasePart { float Transparency; ... // Snip (1 billion lines) void NotifyChanged(char* Name) { ... // Code to call all Lua functions connected to .Changed event }
public: void setTransparency(float newTrans) { Transparency = newTrans; NotifyChanged("Transparency"); } ... }; |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 26 Jul 2012 10:14 PM |
| Note: In an actual C++ class the methods would be defined later, but that isn't actually important right now. |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
| |
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 10:17 PM |
| What is float and void though? (No c++ exp) |
|
|
| Report Abuse |
|
|
Aerideyn
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 1882 |
|
|
| 26 Jul 2012 10:21 PM |
| void means the function does not return anything and float is a number with decimals. (32bit precision) |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 10:23 PM |
Could you explain a little bit further as to what they mean in this context please?
And so I'm guessing the ChildRemoved event gets a NotifyChildRemoved when an object is destroyed or it's parent is set to something else. But what about the touched event? Do you think it uses rays like the other guy said? |
|
|
| Report Abuse |
|
|
|
| 26 Jul 2012 10:36 PM |
No Touched only responds to changes in Physics. Just plain out changing an objects CFrame does not signal .Touched. Now I'm exactly sure how Roblox sets up their events but if you were planning on creating your own events a while loop should be enough.
" Surely not a while true do, that would be very inefficient."
I'm not sure who exactly started this myth but something as simple as
while Part.Position ~= Vector3.new(10, 10, 10) do wait(_time_) end --Code
Will not create any noticable lag spikes. Heck I doubt 100 similar checks would cause a considerable drop in FPS, though I doubt anyone bothered to check before spreading rumors about using loops as events being ineffecient - Not referring to you- |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 10:39 PM |
| What about one of those scripts for each part in the game, just to reference to the one brick that the touched script is in? |
|
|
| Report Abuse |
|
|
| |
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 26 Jul 2012 10:50 PM |
"That's so inefficient though... What about .touched event?"
...
You know Lua only works with C++,C#, other C languages and Haskell right? |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Jul 2012 11:28 PM |
| I don't even know what that means. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 26 Jul 2012 11:38 PM |
@Stygian
Using "Busy-Waiting" loops like that *IS* less efficient.
No, one will not cripple your place. One hundred will not cripple your place. However, if you have, say, 1 of those per brick in your place it will start to add up. Particularly when _time_ is 1/30 of a second.
Why would you use them when a better model (Notify/Events) is an option? The less wasted processor time, the better. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 26 Jul 2012 11:40 PM |
| The touched event is more complicated. What most likely occurs is that a separate method loops through every brick in the place, tests if they are colliding (a much more complex process than it sounds) and calls a NotifyTouched method on both parts. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 26 Jul 2012 11:43 PM |
To add onto my @Stygian post:
Though you are correct in that, in Lua, it's hard to get a noticeable effect (the real problem is in languages where something like this is valid: while not condition do end), it's still a bad habit to get into. |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2012 12:02 AM |
@swm;
It is less effecient than the option of using an event or something similar to notify an action has passed but in cases when thats not available a simple loop should do the job welll enough(of course a reasonable _time_ does not hurt either)
I still agree that this isn't the best idea when you do not have a wait/sleep function like Roblox Lua or other languages |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 27 Jul 2012 12:05 AM |
@Stygian
When is it not available? |
|
|
| Report Abuse |
|
|
|
| 27 Jul 2012 12:10 AM |
Well its not like there's always an event for what we need :P Here's an _old_ script I made
----------------------------------- local a = Workspace.Part1.Position local b = Workspace.Part2.Position local des = {{a.x,b.x},{a.y,b.y},{a.z,b.z}} local pos = Workspace.Part.Position
while ((pos.x<=des[1][1]) or (pos.x>=des[1][2])) or ((pos.y<=des[2][1]) or (pos.y>=des[2][2])) or ((pos.z<=des[3][1]) or (pos.z>=des[3][2])) do
a = Workspace.Part1.Position b = Workspace.Part2.Position des = {{a.x,b.x},{a.y,b.y},{a.z,b.z}} pos = Workspace.Part.Position wait(.3) end
Workspace.Part.BrickColor = BrickColor.new("Bright green") -----------------------------------
Well I don't think there's a special event for checking if a part given region so a simple loop/wait worked well enough |
|
|
| Report Abuse |
|
|