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

GameAPI

Started by YoYoYonnY, 30 December 2013 - 09:35 AM
YoYoYonnY #1
Posted 30 December 2013 - 10:35 AM
Sneak Peak:
Update: Yay! More Progress! I'll probably release v1.1 code next week!



Last Update:

Achievement Notifications!
Currently working on:
Spoiler(better) game engine ( game.start ). replaced with a new engine (requires at least one file now) –> Working on file system; test code:
( shell.run('scripts/script') )
gui for logging in/out and choosing a game. Comming soon.
list of stats, score and achievements. Comming soon.
different kind of stats and default achievements(like "Play a game", "Play ten games", "Save a game") Comming soon.
testing, logging and commenting. (as always) New logging texts
More compact script; rewritten
EDIT: Sorry for this many updates.

I just created a new API that will make storing data for games a bit easier. In this first version:
  • easier game instalation (including pastebin)
  • saving and loading
  • players
  • achievements
  • stats
  • score
Example codes (not tested)
installing a game
Spoilertest

shell.run("gameapi")
game.install( "install" )
game.run("pong")
install

{["game"]="pong",["run"]="shell.run('Games/Games/pong/scripts/script')",["scripts/script"]="term.write('This is a script')",}
adding or removing achievements and score
Spoilertest

shell.run("gameapi")
achievement.add("Play a Game","Play one or more games to unlock.")
scoreboard.add("Gold","Your total amount of gold.")
player.add("YoYoYonnY","Password")
player1 = player.login("YoYoYonnY","Password")
player1 = achievement.unlock( player1, "Play a Game" )
player1 = score.set( player1, "Gold", 100 )
print( "Current Gold:" )
print( player1.score[ "Gold" ] )
player1 = score.remove( player1, "Gold", 20 )
print( "Current Gold:" )
print( player1.score[ "Gold" ] )
print( "Did you play a game?" )
print( tostring( player1.achievements[ "Play a Game" ] ) )
player.logout()
Currently working on:
Spoiler(better) game engine ( game.start ).
gui for logging in/out and choosing a game.
list of stats, score and achievements.
different kind of stats and default achievements(like "Play a game", "Play ten games", "Save a game")
testing (+ more logging).
Download
pastebin get emQ0KxDw gameapi
Edited on 26 January 2014 - 10:51 AM
Zee #2
Posted 05 January 2014 - 07:49 PM
Why do you use
 shell.run("gameapi")
instead of

os.loadAPI("gameapi")
gameapi.install()

EDIT: fix code
Edited on 05 January 2014 - 06:53 PM
YoYoYonnY #3
Posted 08 January 2014 - 10:41 AM
Why do you use
 shell.run("gameapi")
instead of

os.loadAPI("gameapi")
gameapi.install()

EDIT: fix code
Well, I am not exactly sure, but looking at the bios.lua file it will create functions like _G.gameapi.game.install, and I dont need Global table, because not all programs will need my API (games only). So games could enable gameapi, whitout making a mess in the Global table.
EDIT: Also, gameapi.install() wont install gameapi, it will install a new game. BTW, in the original version I used the startup file.
Edited on 08 January 2014 - 09:43 AM
Zee #4
Posted 11 January 2014 - 06:18 PM
I just looked at the code for the API again and noticed that it's a local function. *facepalm*

Thanks for responding.
YoYoYonnY #5
Posted 26 January 2014 - 11:52 AM
BTW, I would like to see some better names for the API and Launcher, because next release v1.1 will probably be out next week.