Mirage Source

Free ORPG making software.
It is currently Sat Apr 27, 2024 7:07 am

All times are UTC




Post new topic Reply to topic  [ 57 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Add()
PostPosted: Mon Oct 16, 2006 3:33 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Hehe :P You wanted more tutorials ;) hehe.

Add:
Code:
Public Function Add(ByVal a As Long, ByVal b As Long)
Add = a + b
End Function


Usage:
Code:
Dim i As Long
i = Add(3, 5)


"i" would result in 8 :) Aint I good ?

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:46 pm 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
Congradulations, you managed to needless slow down and obfuscate the most simple form of math. :lol: :wink:

Though learning how to use functions appropriate is a pretty good thing. Just keep in mind that if you have:

Code:
Public Function MyFunc()


You need to define what type of format it is working in as MyFunc will be handled as a variable. In your example, you are making "Add" a variant (default variable format of a variable without a specified format).

Code:
Public Function MyFunc() As Long


Would make Add return a long.

Sorry, just wanted to point that out in case you didn't know. :wink:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 4:19 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
I never really added that to my mind.. that part has been so obvious so I kinda never learned it :P So thanks for reminding me.

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 4:21 pm 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
I have to say it.

Nesting is your friend! :D


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 4:24 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
At least Add() looks professional :P hehe

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 6:28 pm 
Offline
Knowledgeable

Joined: Wed Jun 14, 2006 10:15 pm
Posts: 169
Code:
Public Function Add(ByVal a As Long, ByVal b As Long)
        Add = a + b
End Function



Awww there ya go Verrigan... lol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 8:43 pm 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
Thats too big of an indent :P


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 8:47 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
and you forgot as long after the function :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 8:11 pm 
Offline
Knowledgeable

Joined: Wed Jun 14, 2006 10:15 pm
Posts: 169
Too long of an indent cuz I did it manually with the spacebar lmao.

Code:
Public Function Add(ByVal a As Long, ByVal b As Long) As Long
     Add = a + b
End Function

There...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 8:29 pm 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
i HATE when people don't nest their code...

isn't it faster just to do

i = 5+3

instead of

i = Add(5,3)

it's less to type... but congrats for submitting something new :wink:

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 12:41 pm 
Offline
Community Leader
User avatar

Joined: Mon May 29, 2006 1:00 pm
Posts: 2538
Location: Sweden
Google Talk: johansson_tk@hotmail.com
Haha..Obsidian, the whole topic was a joke. And you were the only one who didnt get it :P

_________________
I'm on Facebook!My Youtube Channel Send me an email
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 2:57 pm 
Offline
Pro

Joined: Mon May 29, 2006 2:15 am
Posts: 368
oh no i figured it was... :roll:

_________________
Image
Image
The quality of a man is not measured by how well he treats the knowledgeable and competent, but rather how he treats those less fortunate than himself.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 4:04 pm 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
We cant leave subtraction out of the mix.

Code:
Public Function Subtract(ByVal a As Long, ByVal b As Long) as Long
         Subtract = a - b
End Function


Code:
Public Function Multiply(ByVal a As Long, ByVal b As Long) as Long
         Multiply = a * b
End Function


Code:
Public Function Divide(ByVal a As Long, ByVal b As Long) as Long
         Divide = a / b
End Function


There now the basic math functions don't feel left out.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 6:16 pm 
Offline
Regular

Joined: Mon Jun 12, 2006 10:10 pm
Posts: 68
I dare somebody to do square root without the "Sqrt()" functon...

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 6:55 pm 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
Code:
Public Function SquareRoot(ByVal a As Double) as Double
         SquareRoot=a^(1/2)
End Function


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 8:17 pm 
Offline
Knowledgeable

Joined: Wed Jun 14, 2006 10:15 pm
Posts: 169
Rofl, how about percentage? :p


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 9:07 pm 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
http://en.wikipedia.org/wiki/Methods_of ... uare_roots

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 10:35 pm 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
Misunderstood wrote:
Code:
Public Function SquareRoot(ByVal a As Double) as Double
         SquareRoot=a^(1/2)
End Function
Is that method faster than Sqr(num)? :P


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 11:55 pm 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
Code:
Public Sub TestOne(ByVal Index As Long)
Dim a As Single
   
    a = Sqr(LookupTable(Index))
   
End Sub


Code:
Public Sub TestTwo(ByVal Index As Long)
Dim a As Single
   
    a = LookupTable(Index) ^ 0.5
   
End Sub


Code:
%Faster   -98.4|   -98.4|   -98.4|   -98.4|   -98.4|   -98.4|   -98.5|   -98.4|   -98.4|   -98.4
Test1       162|     160|     169|     161|     160|     161|     159|     161|     160|     161
Test2     10272|   10262|   10263|   10283|   10281|   10274|   10278|   10267|   10258|   10265


Nope. Not by a long shot. :wink:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 1:18 am 
Offline
Pro

Joined: Sat Jun 03, 2006 8:32 pm
Posts: 415
Leighland wrote:
Rofl, how about percentage? :p


What do you mean?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 1:36 am 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
Thanks, Spodi. Is that in the IDE, or compiled?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 2:08 am 
Offline
Pro

Joined: Mon May 29, 2006 1:40 pm
Posts: 430
Right, raising to the .5 is generally much slower in most programing languages than the buit in sqrt function.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 2:34 am 
Offline
Knowledgeable
User avatar

Joined: Mon Jul 24, 2006 2:04 pm
Posts: 339
Compiled, 5000 loops per each result. :wink:

_________________
NetGore Free Open Source MMORPG Maker


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 3:00 am 
Offline
Knowledgeable
User avatar

Joined: Sun May 28, 2006 10:07 pm
Posts: 327
Location: Washington
Thanks. I was at work, and didn't have access to mah VB compiler. :P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 4:37 am 
Offline
Banned
User avatar

Joined: Mon Jun 05, 2006 9:22 pm
Posts: 394
Location: USA
Code:
Public Function Perct(By Val X as Double, By Val Per as Double) as Double
     Perct = X * (Per/100)
End Function


Perc(X, Per)

So it would output the percentile. :)

Already built in functions include:

Abs - Absolute Value
Sin, Cos. Tan (Sine Cosine Tangent)
Exp - base log e raised to specified power
log - logarithm (sp?)
Atn - Inverse tangent

Sqr - Square Root

Here are some nifty functions I found for CSC, SEC, and COT

Code:
Public Function Sec(ByVal angle As Double) As Double
    ' Calculate the secant of angle, in radians.
    Return 1.0 / Math.Cos(angle)
End Function

Public Function Csc(ByVal angle As Double) As Double
    ' Calculate cosecant of an angle, in radians.
    Return 1.0 / Math.Sin(angle)
End Function

Public Function Cot(ByVal angle As Double) As Double
    ' Calculate cotangent of an angle, in radians.
    Return 1.0 / Math.Tan(angle)
End Function



PS: Forumals to make the Inverse of the Trig Functions:

Inverse sine (Asin(x))
Atan(x / Sqrt(-x * x + 1))

Inverse cosine (Acos(x))
Atan(-x / Sqrt(-x * x + 1)) + 2 * Atan(1)

Inverse secant (Asec(x))
2 * Atan(1) – Atan(Sign(x) / Sqrt(x * x – 1))

Inverse cosecant (Acsc(x))
Atan(Sign(x) / Sqrt(x * x – 1))

Inverse cotangent (Acot(x))
2 * Atan(1) - Atan(x)

For those who don't remember trig, these forumals are derviced ALL from using the MANY Trig Identities altered to use TANGENT! Gah.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 57 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group