I am currently working on Ex 52 of learn python the hard way and am trying to figure out how to implement the 10 tries for the safe code in the laser weapon armory. After a couple attempts I am currently at this point where I try to use a while loop in the app.py code if the current session is 'laser_weapon_armory and the count is less than 9. When I put print in the code I can see that I am in fact entering the loop but that the web page does not reload after this first attempt (the count simply increases each loop until it reaches the exit point and then I go to the death scene). Any input on what I could do differently would be greatly appreciated.
In the mean time I will continue to try to work through this problem.
# from flask import Flask, session, redirect, url_for, escape, request from flask import render_template from gothonweb import planisphere app = Flask(__name__) @app.route("/") def index(): #this is used to "setup" the session with starting values session['room_name'] = planisphere.START return redirect(url_for("game")) @app.route("/game", methods = ['GET', 'POST']) def game(): count = 0 room_name = session.get('room_name') if request.method == "GET": if room_name: room = planisphere.load_room(room_name) return render_template("show_room.html", room = room) else: # why is this here? do you need it? return render_template("you_died.html") else: current_room = planisphere.load_room('laser_weapon_armory') while session['room_name'] == 'laser_weapon_armory' and count <= 9: count +=1 print(count) session['room_name'] = current_room.go('stay') action = request.form.get('action') action = request.form.get('action') if room_name and action: room = planisphere.load_room(room_name) next_room = room.go(action) death_room = room.go('*') if not next_room: session['room_name'] = planisphere.name_room(death_room) else: session['room_name'] = planisphere.name_room(next_room) return redirect(url_for("game")) if __name__ == "__main__": app.run()
edit: forgot to mention that in session[‘room_name’] = current_room.go(‘stay’) I made a path in planispheres for the laser_weapon_armory that maps ‘stay’ to laser_weapon_armory in an attempt to try to reload that original page