350 posts
Posted 04 April 2014 - 10:44 PM
RoDHabilitis
(form the latin the mental or physical power to do something.)
The ability to code better, and faster in your hands.
This is a simple, yet useful API, in wich you can calculate the probability of a certain event, do some simple math and has some file management functions.
Functions:Spoiler
prob.calc(prob, max)
Spoiler
It returns true or false based on the first parameter(percentage).
The user can also type the second parameter to increase the maximium percentage (if nothing is typed it will calculate up to 100%)
Example:
I want to create a rainy day, but i only want it to have 30% chances of raining:
rain = prob.calc(30)
if rain == true then
print("Ist raining")
else
print("Dry day")
end
prob.mean(table)
Spoiler
It returns the mean of the table numbers. The mean is like: 3+9+9+4 = 25
25/4 = 6.25
Basicly it finds what is the intermediate value of a table(only numbers, ofc)
Example:
I want to find the mean of the table age:
age = {3,5,2,8}
meanAge = prob.mean(age)
print(meanAge)
Simple huh?
prob.round(num, idp)
Spoiler
This function rounds a number to one digit(default), you can enter the digits to be rounded.
rnd = prob.round(6.25)
print(rnd)
File management functions:Spoiler
prob.writeFile(filename, content, overwrite)
Spoiler
it opens a file, writes the content, closes and all in one line. No more file = fs.open bla bla bla.
If overwirte is true the function will overwrite the file.
prob.writeFile("myfile", "this is my file", true)
If there is a file called myfile, the function will delete the content and write "this is my file".
prob.readFile(filename)
Spoiler
it opens a file, reads it, returns the content. Simple.
cnt = prob.readFile("myfile")
print(cnt)
Outputs "this is my file".
prob.pack(table, folder)
Spoiler
prob.pack(table, folder)
This one is useful to move multiple files.
The user write the filenames in the table and then just say where do they should go.
tb={"main" , "player", "enemy", "map"}
prob.pack(tb, "mygame/resources")
.
Thats it for now.
I will try to add even more functions! The more the best.
Just with this API you can save a lot of time(it compensates the time lost for installing the API, for granted)
Remember/for the new users to use:
os.loadAPI("prob")
In the beginning of your code so you can use it later.
Download:pastebin get
ibmV08aj prob
Edited on 06 April 2014 - 08:01 PM
1029 posts
Location
Missouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension
Posted 04 April 2014 - 10:52 PM
Why not just use the builtin math apis?
350 posts
Posted 04 April 2014 - 10:56 PM
Why not just use the builtin math apis?
Becasue you just need to do prob.calc(bla, bla)
4 or 5 lines compressed to one line, and because the user get more aware of the numbers he's using.
Is so simple that i just look at the first parameter and i already know that thats a 20% chance of raining for example.
And ofc the maximum parameter that gives more possibilities to the API.
Edit: Basicaly, time saved, less confusion and more easy to use than the math apis, :)/>
Edited on 04 April 2014 - 08:57 PM
1281 posts
Posted 04 April 2014 - 11:06 PM
Not really compressing 5 lines.
rain = (chance > math.random(1,100))
500 posts
Posted 04 April 2014 - 11:16 PM
Not really compressing 5 lines.
rain = (chance > math.random(1,100))
That doesn't localize, has superfluous parenthesis, uses '>' when it should be '>=', and does math.random(1, 100) when you can just do math.random(100).
local occurs = chance >= math.random(max)
Edited on 04 April 2014 - 09:17 PM
350 posts
Posted 04 April 2014 - 11:17 PM
Not really compressing 5 lines.
rain = (chance > math.random(1,100))
Yeah kinda true… But if you dont type the second parameter it will assume 100 (general percentage calculation), and its faster to type
rain = prob.calc(10)
i mean, maybe this is a little unusefull, but all the seconds count and the user is more focused just one the percentage(no worries about the minimum and maximum).
Maybe i will add some new features to the API, to be more usefull, thanks.
Edited on 04 April 2014 - 09:18 PM
7508 posts
Location
Australia
Posted 04 April 2014 - 11:36 PM
the localised definition of error at the bottom of your script isn't used… also you should use an error throwback level of 2 on your APIs so that when you are telling them about incorrect usage it blames their program and not your API. Error call syntax
error( message, [throwback] )
1281 posts
Posted 04 April 2014 - 11:53 PM
That doesn't localize, has superfluous parenthesis, uses '>' when it should be '>=', and does math.random(1, 100) when you can just do math.random(100).
It's like you jus threw the whole point out the window and said "I don't wanna!"…
The parenthesis is a personal preference of mine.
1029 posts
Location
Missouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension
Posted 05 April 2014 - 03:15 AM
If seconds count, then the 1.5 minutes it will take the user to decide weather to install the API, make a spot for it, and load it into the program is not worth it. That's not even mentioning how long it'd take to put in the installer.
Maybe if this was a tiny portion of a utilities API or something a program maker put at the time of his code and wrote himself to make it easier, but considering it's not, you might want to think of a creative way you could make this API more useful. You could make it into a utilities API and add a bunch of random functions, or think of something creative.
Edited on 05 April 2014 - 01:18 AM
350 posts
Posted 05 April 2014 - 12:37 PM
If seconds count, then the 1.5 minutes it will take the user to decide weather to install the API, make a spot for it, and load it into the program is not worth it. That's not even mentioning how long it'd take to put in the installer.
Maybe if this was a tiny portion of a utilities API or something a program maker put at the time of his code and wrote himself to make it easier, but considering it's not, you might want to think of a creative way you could make this API more useful. You could make it into a utilities API and add a bunch of random functions, or think of something creative.
Thanks, thats exacltly what i am doing right now :)/>
So far there is a mean calcutation(wich can be loaded from a table):
example:
1+4+7+3 / 4
i added a round function:
3.24 = 3
and i am planing adding a lot more. :)/>
Edited on 05 April 2014 - 03:37 PM