This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
CaptainPi's profile picture

Calculator for Pocket

Started by CaptainPi, 23 January 2017 - 10:50 AM
CaptainPi #1
Posted 23 January 2017 - 11:50 AM
Hey guys. Here a little computer app for the pocket that I made up. It does simple math but can also square root and I'm planning of adding trig. You'll need my button api to use it.

Button API: pastebin.com/x71BzgKb
Calculator: pastebin.com/5v4aar72

To load an api goto your startup file and type
os.loadAPI("api_dir/button")

Bugs include:
Performing arithmetic with unreal numbers (I haven't figured out how to stop it before it errors. If anyone can help it'll be appreciated)

If anyone has any ideas or found anymore bugs please reply
Edited on 23 January 2017 - 07:57 PM
Bomb Bloke #2
Posted 24 January 2017 - 10:54 AM
To load an api goto your startup file and type
os.loadAPI("api_dir/button")

It'd be a bit more convenient to have the calculator script load any custom APIs it requires itself.
CaptainPi #3
Posted 27 January 2017 - 01:41 AM
To load an api goto your startup file and type
os.loadAPI("api_dir/button")

It'd be a bit more convenient to have the calculator script load any custom APIs it requires itself.

Yes but that would be if you only used the api for this. I use it in many of my programs so I personally wouldn't put it in there since the page I use to get in there uses the api. But if you only use it for this I'm sure the person who uses this can type the loadAPI at the start of the calculator script instead of the startup.
supernicejohn #4
Posted 27 January 2017 - 07:33 AM
From what I can see, all button objects are stored locally in the program, not the API itself, and as such, reloading the API shouldn't reset any of those.
It's quite a cool idea to use Lua's built in evaluation, nice shortcut!
CaptainPi #5
Posted 27 January 2017 - 08:06 AM
From what I can see, all button objects are stored locally in the program, not the API itself, and as such, reloading the API shouldn't reset any of those.
It's quite a cool idea to use Lua's built in evaluation, nice shortcut!

Thanks John :)/> I find it just makes the code a bit shorter and easier to make adjustments. Now instead of making 15 changes all over the place I only change 1 line at the top and it does the rest. Also don't have to worry about centering everything.
Bomb Bloke #6
Posted 27 January 2017 - 11:03 AM
From what I can see, all button objects are stored locally in the program, not the API itself, and as such, reloading the API shouldn't reset any of those.

Even if it did reset them:

if not button then os.loadAPI("api_dir/button") end

This could be furthermore expanded to check whether the API file exists, and to download it if it doesn't.
Edited on 27 January 2017 - 10:05 AM
CaptainPi #7
Posted 28 January 2017 - 12:32 AM
if not button then os.loadAPI("api_dir/button") end

This could be furthermore expanded to check whether the API file exists, and to download it if it doesn't.

Ok why?
Bomb Bloke #8
Posted 28 January 2017 - 01:14 PM
Again, simple convenience. Why should a user have to manually install APIs a script requires if that script can do it for them?
CaptainPi #9
Posted 28 January 2017 - 11:02 PM
Ok I added it to the script but you'll still need to edit the dir
Lupus590 #10
Posted 28 January 2017 - 11:55 PM
if not button then os.loadAPI("api_dir/button") end

This could be furthermore expanded to check whether the API file exists, and to download it if it doesn't.

Like this I would assume.

Edit: which I've just realised is sourced from a post by Bomb Bloke
Edited on 28 January 2017 - 11:02 PM
CaptainPi #11
Posted 29 January 2017 - 01:50 AM
if not button then os.loadAPI("api_dir/button") end

This could be furthermore expanded to check whether the API file exists, and to download it if it doesn't.

Like this I would assume.

Edit: which I've just realised is sourced from a post by Bomb Bloke

When I start posting more sets of scripts at a time I was planning to learn how to download files from the Internet in game. Just haven't had the chance to figure it out and figured 2 files wasn't a hassle.