Scripts
|
Size: 279
Comment:
|
Size: 2831
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 4: | Line 4: |
| = Creating .accomplishment files = [[Accomplishments/CreatingGuide/AccomplishmentFile|<-- Previous page (Creating .accomplishment files)]] - - - - - [[Accomplishmens|Next page (blah) --->]] |
= Creating accomplishment scripts = [[Accomplishments/CreatingGuide/AccomplishmentFile|<-- Previous page (Creating .accomplishment files)]] - - - - - [[Accomplishments|Next page (blah) --->]] '''This page is under construction. This guide is not yet complete!''' Every single accomplishment requires a script, that is executed to determine whether the user has completed this accomplishment. Usually these scripts are not larger then the .accomplishment file, so no great programming skills are needed to prepare one. Currently only Python scripts are supported. We hope to allow developers to prepare scripts in other languages too, but that's not our priority, while writing them in Python is simple and quick. ===== Returning values ===== The Accomplishments System will run scripts on it's own. The only thing the script has to do is to check if the accomplishment is complete, and report result by returning a number. The exit codes are: * '''0''' - The accomplishment has been completed. * '''1''' - The accomplishment has not been completed. * '''2''' - There was an error while checking for completion. * '''4''' - There was an error while getting extra-information. The easiest way to return such value is to use `sys.exit(n)`. <<BR>> While this should be enough for you to create scripts, there are some tips and examples for you, to make everything clearer. Also, if your script has to use some '''extra-information''', it can use Accomplishments Daemon API to get it - details below. Everything your script prints will land in daemon's log - which is available at ~/.cache/accomplishments/daemon.log == Local accomplishment scripts == ===== Example ===== {{{ #!/usr/bin/python import traceback, sys try: try: #open the highscores file... highscoresfile = open("/var/games/gnomine.Small.scores") except IOError as e: # it seems that the file does not exist sys.exit(1) bestscore = highscoresfile.readline() if not bestscore: #the file is empty sys.exit(1) #the file is not empty sys.exit(0) except: traceback.print_exc() sys.exit(2) }}} This is a working script for '''Begginer Minesweeper''' from previous chapter. It is intended to check if the user has ever completed a Small game in Gnomine. This is done by reading the highscores file, and checking whether it contains at least one entry. If so, we return 0, otherwise 1. All that is within a global ''try'' block, to react in case of unhandled errors (that does not make much sense here, but may be useful in your scripts, so it's just as an example). == Global accomplishment scripts == == Testing your scripts == |
The Guide to Creating Your Accomplishments
Creating accomplishment scripts
<-- Previous page (Creating .accomplishment files) - - - - - Next page (blah) --->
This page is under construction. This guide is not yet complete!
Every single accomplishment requires a script, that is executed to determine whether the user has completed this accomplishment. Usually these scripts are not larger then the .accomplishment file, so no great programming skills are needed to prepare one.
Currently only Python scripts are supported. We hope to allow developers to prepare scripts in other languages too, but that's not our priority, while writing them in Python is simple and quick.
Returning values
The Accomplishments System will run scripts on it's own. The only thing the script has to do is to check if the accomplishment is complete, and report result by returning a number.
The exit codes are:
0 - The accomplishment has been completed.
1 - The accomplishment has not been completed.
2 - There was an error while checking for completion.
4 - There was an error while getting extra-information.
The easiest way to return such value is to use sys.exit(n).
While this should be enough for you to create scripts, there are some tips and examples for you, to make everything clearer.
Also, if your script has to use some extra-information, it can use Accomplishments Daemon API to get it - details below.
Everything your script prints will land in daemon's log - which is available at ~/.cache/accomplishments/daemon.log
Local accomplishment scripts
Example
import traceback, sys
try:
try:
#open the highscores file...
highscoresfile = open("/var/games/gnomine.Small.scores")
except IOError as e:
# it seems that the file does not exist
sys.exit(1)
bestscore = highscoresfile.readline()
if not bestscore:
#the file is empty
sys.exit(1)
#the file is not empty
sys.exit(0)
except:
traceback.print_exc()
sys.exit(2)This is a working script for Begginer Minesweeper from previous chapter. It is intended to check if the user has ever completed a Small game in Gnomine. This is done by reading the highscores file, and checking whether it contains at least one entry. If so, we return 0, otherwise 1. All that is within a global try block, to react in case of unhandled errors (that does not make much sense here, but may be useful in your scripts, so it's just as an example).
Global accomplishment scripts
Testing your scripts
Accomplishments/CreatingGuide/Scripts (last edited 2012-05-01 15:34:32 by 99-41-167-234)
