Hey Ashley and co,
Apologies for leaving this thread for so long. Been some crazy stuff going on so have been looking after my boy full time for a while.
I have made some wonderful progress so far and I think flask and construct are a lush match for anyone wanting to move away from php or who already have python experience from construct 1.
I will write a complete tutorial to help people get started when I have the time however I will share some of the possibilities now.
Also I have a missing feature for you Ashley: The ability to set custom save paths for the runtime file so that it doesn't need to be manually edited, no biggie but it speeds things up:
On a flask site the folder structure is like this:
app.py (in the root)
/templates (folder for templates, ie this is where html of the game lives)
/static (all static files so I have the basic runtime files in here then subfolders /images and /media)
My app looks like this:
app.py
/static
/static/allthejquerybits.js
/static/mygamename/runtime and appcache.js
/static/mygamename/media/myaudio.ogg
/static/mygamename/images/myimages.png
/templates/game.html
I edit the html to reflect this and when I export the project I set the right paths for images and media so I don't have to do it manually for every file in the runtime js.
As far as things you can easily do (I will make a full tutorial on flask soon enough) here is a quick one.
On an ubuntu dev box install pip:
sudo apt-get install python-pip
sudo pip install flask
Create a directory called "mygame" to store your files.
make two sub directories called "static" and "templates" we will come back to these.
Make a new file called app.py in your mygame directory.
paste this into it:
###################################
#import your dependancies
from flask import Flask, request, render_template
#Set key for encrypting cookies
SECRET_KEY = 'development key'
#Turn on debug mode
DEBUG = True
#define app
app = Flask(__name__)
app.debug = DEBUG
app.secret_key = SECRET_KEY
#create our method called funnysentance
#Start with defining the route
—('/funnysentance')
#define your function
def funnysentance():
#fetch arguments from url using request.args.get
a = request.args.get('a', None)
b = request.args.get('b', None)
#make the funny sentance
c = a+" make me happy in the "+b
#return the result to the browser/ajax
return c
#render your game on a url
—("/mygame")
def mygame():
#render the html
return render_template('mygame.html')
#set up the app to run
if __name__ == '__main__':
app.run(host='0.0.0.0')
########################
Open a command prompt on the path of this file and type python app.py
Open a browser and put this in the url bar:
127.0.0.1/funnysentance
You will get your sentance using the variables parameters in the url.
Make a simple game with a button and a text box, when the button is clicked it makes an ajax call to:
127.0.0.1/funnysentance
and sets the text in the text box to AJAX.lastData
Export the files making sure you put your template renamed mygame.html into the "templates" folder
Put the c2runtime files in the "static" folder and make sure you change the path of c2runtime.js in your mygame.html file. If you do use images and sounds be sure to place their folders in the "static" folder. When you export the project append static to the paths of media and images and this will make sure you have the right paths in runtime.js.
Still with me?
Good
Navigate to 127.0.0.1/mygame and you should see your game, click the button and you should get a sentance in your text box using the url encoded variables.
If you are using a headless server not an ubuntu desktop vm just navigate to serverip/mygame and you should see it.
Cool I should get some actual work for money done now. Hope you guys enjoyed this. I will do a bigger tutorial involving databases and other fun things as soon as poss.
Mike