Quote: "(1) I want to develop a single function to average 2-5 numbers really quickly,"
This is a much quicker (easier, coding-wise method) but if you want more flexibility, stick with zeroSlave's example. It depends largely on the application.
av45# = Average(0,4,0,0,5)
PRINT "The average of 4 and 5 is: " + STR$(av45#)
PRINT "The average of 1, 2, 3, 4 is: " + STR$(Average(1,2,3,4,0))
PRINT "The average of -10 and -20 is: " + STR$(Average(-10,-20,0,0,0))
PRINT "": PRINT "Press any key...": WAIT KEY: END
Function Average(n1#, n2#, n3#, n4#, n5#)
avg# = 0.0 `DBPro needs decimals in a var to output decimals from a var. Think of this as the equivilent to "float avg" in C++
ctr = 0 `Insurance. I always assign INCremented variables a zero value before use (prevents any possibility of unwanted behaviou).
IF n1# <> 0: INC avg#, n1#: INC ctr: ENDIF
IF n2# <> 0: INC avg#, n2#: INC ctr: ENDIF
IF n3# <> 0: INC avg#, n3#: INC ctr: ENDIF
IF n4# <> 0: INC avg#, n4#: INC ctr: ENDIF
IF n5# <> 0: INC avg#, n5#: INC ctr: ENDIF
IF avg# <> 0: avg# = avg# / ctr: ENDIF
EndFunction avg#
Quote: "(2) I want a function that removes everything after a set of parentheses, and another that takes everything before it. I also want it to ignore spaces."
Here's a basic example. It's not the best but you can customize it. Have a look at the string-manipulation function in the DBP help. If used correctly, you only ever need the LEFT$, RIGHT$ and LEN functions. However, the others like MID$ and FIND FIRST TOKEN$ make life a lot easier.
mystat$ = "intelligence(30%)"
PRINT "Original Text: " + mystat$
PRINT GetString$(mystat$)
PRINT GetValue(mystat$)
PRINT "": PRINT "Press any key...": WAIT KEY: END
Function GetString$(txt$)
ret$ = FIRST TOKEN$(txt$, "(")
EndFunction ret$
Function GetValue(txt$)
tmp$ = FIRST TOKEN$(txt$, ")")
ccount = FIND FIRST CHAR$(txt$, "(")
tmp$ = RIGHT$(tmp$, LEN(tmp$) - ccount)
ret# = VAL(tmp$)
EndFunction ret#
Quote: "Related to 2, how do I reliably turn a percentage in the form of a string into a decimal for calculation?"
What zeroSlave said
Quote: "Can someone link me to a page explaining the types of values and what numbers they can store?
"
Open a blank file in the editor, press F1. Click "Principles" then "Datatypes and variables". All you basically need to know.
Quote: "Also, I'm really confused as to how RGB values behave when input into functions,"
The other thing zeroSlave said.
Quote: "Hope this helps and isn't to confusing."
It shouldn't be. In fact you could be writing tutorials. That was very well put and a lot more coherent then many of the "|-|0\/\/ |-0 c0|)3 ||\| |-3|-| Darkbasicz"* floating about the web.
Translation:
"|-|0\/\/ |-0 c0|)3 ||\| |-3|-| Darkbasicz"
"How to code in t3h Darkbasicz"
After countless volumes of Megatokyo, one gets to understand
some of this...err...language, scarily.