I think I almost got it
Code: Select all
default chess_answer_list =[]
default chess_pieces_list = ["King","Queen","Rook","Bishop","Knight","Pawn"]
default chess_pieces_values = ["10","9","5","3","3","1"]
default math_signs_list = ["Multiply","Divide","Add","Subtract","Equals","Question"]
default math_signs = [ '*', '/', '+', '-' ]
default pieces = []
default signs = []
screen chessBoardOptions:
imagebutton:
idle "backgrounds/transparent.png"
action [Hide ("chessBoardOptions") ]
imagebutton:
idle "boxes/playChessG.png"
hover "boxes/playChessH.png"
action [Hide ("chessBoardOptions"), Jump("play"+itemClickedOn)]
xpos 460
ypos 890
imagebutton:
idle "boxes/investigateG.png"
hover "boxes/investigateH.png"
action [Hide ("chessBoardOptions"), Jump ("investigate" +itemClickedOn)]
xpos 1060
ypos 890
label investigateChessBoard:
$ hideScreens()
p "It's a board made of Chess."
jump expression location
label playChessBoard:
$ speaker = "bethany"
p "Let's D-D-D-Duel"
$ hideScreens()
show countdown at Position(xalign=.1, yalign=.1)
$ ui.timer(5.0, ui.jumps("slow"))
show screen math_test()
$ pieces = [ renpy.random.choice(chess_pieces_list) for k in range(3) ]
$ signs = [ renpy.random.choice(math_signs_list) for k in range(2) ]
$ chess_answer = 50
#$ chess_answer = renpy.python.py_eval( "".join( [
# chess_pieces_values[chess_pieces_list.index[pieces[0]]],
# math_signs[math_signs_list.index[signs[0]]],
# chess_pieces_values[chess_pieces_list.index[pieces[1]]],
# math_signs[math_signs_list.index[signs[1]]],
# chess_pieces_values[chess_pieces_list.index[pieces[2]]] ] ) )
$ generate_random_menu(chess_answer)
$ user_answer = menu(chess_answer_list)
$ renpy.hide_screen("math_test")
if user_answer:
show expression ( speaker + " happy")
$ renpy.say(getattr(store, speaker[0]), "Right answer")
else:
show expression ( speaker + " disgusted")
$ renpy.say (getattr(store, speaker[0]), "Wrong answer")
$ speaker = "noOne"
jump expression location
label slow:
$ renpy.hide_screen("math_test")
hide countdown
"You're too slow."
$ speaker = "noOne"
jump expression location
screen math_test():
hbox:
add pieces[0]
add signs[0]
add pieces[1]
add signs[1]
add pieces[2]
add "Equals"
init 2 python:
def generate_random_menu(correct_value):
global chess_answer_list
chess_answer_list.append( (str(correct_value), True))
chess_answer_list.append( (str(correct_value + renpy.random.randint(0, 5)), False))
chess_answer_list.append( (str(correct_value - renpy.random.randint(0, 5)), False))
chess_answer_list.append( (str(correct_value + renpy.random.randint(0, 5)), False))
chess_answer_list.append( (str(correct_value - renpy.random.randint(0, 5)), False))
This works perfectly except for the line I commented out.
Code: Select all
$ chess_answer = renpy.python.py_eval( "".join( [
chess_pieces_values[chess_pieces_list.index[pieces[0]]],
math_signs[math_signs_list.index[signs[0]]],
chess_pieces_values[chess_pieces_list.index[pieces[1]]],
math_signs[math_signs_list.index[signs[1]]],
chess_pieces_values[chess_pieces_list.index[pieces[2]]] ] ) )
That gives me the getItem error again.
I don't understand it should work. Let's say pieces[0] = "Rook". Then chess_pieces_list.index["Rook"] = 2. Then chess_pieces_values [2] = "9". Even if I wrap the correct parts with int(). It still doesn't work. I suspect the problem is chess_pieces_list.index["Rook"]