miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 17 Dec 2011 04:58 PM |
print(math.abs(-10))
--10
So math.abs means it prints the integer? The positive number.. What if you have a decimal?
print(math.pow(6,3))
--72
So that is just for exponents... |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 17 Dec 2011 05:13 PM |
math.abs returns the absolute value of a number.
print(math.abs(-5.2)) >5.2
print(math.abs(5.2)) >5,2
Don't use math.pow, it's unnecessary typing. Just use the ^ operator.
Kind of off-topic, but here's another way to get absolute value:
math.sqrt((x)^2) |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 17 Dec 2011 05:14 PM |
| math.sqrt is unnecessary typing too. Just use x^.5 |
|
|
| Report Abuse |
|
|
|
| 17 Dec 2011 05:15 PM |
@Spectrum
x^.5 doesn't always work for some things. |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 17 Dec 2011 05:16 PM |
| Example please? (And don't come with negative numbers) |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 17 Dec 2011 05:17 PM |
@Tears Actually, it WILL work for everything. I just use math.sqrt because x^0.5 is ugly. |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 17 Dec 2011 05:19 PM |
Well, it depends on how you look at it:
If x = -5:
x^0.5 = -2.236
(x)^0.5 = error |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 17 Dec 2011 05:33 PM |
@blockoo and spectrum
So If I said
print(3^3)
--27
and I printed
print(math.pow(3,3))
--27
What's more efficient?
And why do some people use exponents? |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 17 Dec 2011 05:44 PM |
| The more efficient one is the one that requires less typing. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 17 Dec 2011 05:57 PM |
-_-
for i,v in pairs(game.Workspace.miz656:GetChildren()) do if v.ClassName == "Part" then v.Transparency = 1 end end
game.Workspace.miz656.Torso.Transparency = 1 game.Workspace.miz656.Head.Transparency = 1 game.Workspace.miz656[Left Arm].Transparency = 1 game.Workspace.miz656[Right Arm].Transparency = 1 game.Workspace.miz656[Left Leg].Transparency = 1 game.Workspace.miz656[Right Leg].Transparency = 1
That's more efficient than the first script and requires more typing... |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 17 Dec 2011 06:52 PM |
| That second one is DEFINITELY not more efficient. |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 17 Dec 2011 07:37 PM |
@miz
Though technically the second one may run faster, the difference does not justify the additional work in writing the script and editing it. |
|
|
| Report Abuse |
|
|
iamogggg
|
  |
| Joined: 09 Sep 2008 |
| Total Posts: 642 |
|
| |
|
|
| 17 Dec 2011 08:18 PM |
"And why do some people use exponents?"
...math.pow and ^ both indicate exponentiation.
You now have +10 INT from this post. Oh, by the way, Like an __AWESOME__ boss- |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 17 Dec 2011 10:08 PM |
@iam
No, it does not. A few milliseconds at most of computer time does not justify several seconds of my time when I edit the script; it's a REALLY bad precedent to set when you have longer loops. |
|
|
| Report Abuse |
|
|
Zarcius
|
  |
| Joined: 08 Dec 2007 |
| Total Posts: 3024 |
|
|
| 17 Dec 2011 10:37 PM |
I attempted to explain this all to him through PMs...
Didn't listen to me, either. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 18 Dec 2011 01:54 PM |
@swmaniac and blockoo
Kingkiller1000 said the second script is more efficient...AND THAT GUY IS AN EXPERT SCRIPTER! |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 18 Dec 2011 01:57 PM |
@miz *Facedesk* Ok, go waste your time for a .000003% faster code. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 18 Dec 2011 02:08 PM |
@spectrumw
Does it matter? I know I can use a for loop -_- AND I DO!!! But that script to me is just like saying
Humanoid.Health = 0 Humanoid:TakeDamage(100)
Same thing...
3^3 = 27
math.pow(3,3)--27
Same thing...
script.Parent = nil script:Remove()
Same thing... Pretty much |
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 18 Dec 2011 02:15 PM |
My point is; 3 ^ 3 is faster to type while math.pow(3, 3) isn't. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 18 Dec 2011 02:24 PM |
Sometimes I'm lazy, sometimes I'm not...
And when is there a chance I usually use a mathmatical function besides math.random().... |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 19 Dec 2011 07:01 PM |
"Kingkiller1000 said the second script is more efficient...AND THAT GUY IS AN EXPERT SCRIPTER!"
And I guarantee that he didn't mean efficient like that. Or that efficiency to that extent is desirable. If he honestly believes that it's better to save milliseconds of computer time than to maintain readable and editable code, he does not qualify as an expert programmer.
Yes, your script will run faster on the computer, but the difference is MILLISECONDS AT BEST. Since Roblox only refreshes the image on a person's screen every 1/30 of a second, the player won't even notice the difference.
On the other hand, you've hextupled (6x) your work if you ever want to edit that script. |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 19 Dec 2011 08:30 PM |
| Efficiency is a combination of the work required and the effectiveness/reliability. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2011 08:32 PM |
| miz, you really don't ever listen, do you? |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 19 Dec 2011 08:32 PM |
"x^.5 doesn't always work for some things."
But it does. sqrt(x) is, by definition x^(1/2), which can also be written as x^0.5.
---------- ~ pwnedu46, the unicorn ~ |
|
|
| Report Abuse |
|
|