- Sep 27, 2018
- 270
- 376
I need some help with menu's,
I have list where the player can choose to swap two items which is presented via a menu.
It only shows the items after his current position in the list (stagePath):
Is there a way I can incorporate a for/while loop as this list can grow and shrink?
The following code works but it assumes there is never more than 12 list items and it is very code inefficient.
I have tried to use renpy.display_menu() but it's 2:30am I am half asleep. It isn't throwing any errors, but also it's not displaying anything.
I have list where the player can choose to swap two items which is presented via a menu.
It only shows the items after his current position in the list (stagePath):
Is there a way I can incorporate a for/while loop as this list can grow and shrink?
The following code works but it assumes there is never more than 12 list items and it is very code inefficient.
Code:
menu:
"Choose a card to swap"
"[deckPath[1][1]]" if stagePath < 1:
$swapFirstValue = 1
"[deckPath[2][1]]" if stagePath < 2:
$swapFirstValue = 2
"[deckPath[3][1]]" if (stagePath < 3) and 3 < len(deckPath):
$swapFirstValue = 3
"[deckPath[4][1]]" if (stagePath < 4) and 4 < len(deckPath):
$swapFirstValue = 4
"[deckPath[5][1]]" if (stagePath < 5) and 5 < len(deckPath):
$swapFirstValue = 5
"[deckPath[6][1]]" if (stagePath < 6) and 6 < len(deckPath):
$swapFirstValue = 6
"[deckPath[7][1]]" if (stagePath < 7) and 7 < len(deckPath):
$swapFirstValue = 7
"[deckPath[8][1]]" if (stagePath < 8) and 8 < len(deckPath):
$swapFirstValue = 8
"[deckPath[9][1]]" if (stagePath < 9) and 9 < len(deckPath):
$swapFirstValue = 9
"[deckPath[10][1]]" if (stagePath < 10) and 10 < len(deckPath):
$swapFirstValue = 10
"[deckPath[11][1]]" if (stagePath < 11) and 11 < len(deckPath):
$swapFirstValue = 11
"None...":
$skipSwap = False
if skipSwap:
menu:
"Choose the card to swap with"
"[deckPath[1][1]]" if stagePath < 1 and swapFirstValue != 1:
$swapSecondValue = 1
"[deckPath[2][1]]" if stagePath < 2 and swapFirstValue != 2:
$swapSecondValue = 2
"[deckPath[3][1]]" if (stagePath < 3) and 3 < len(deckPath) and swapFirstValue != 3:
$swapSecondValue = 3
"[deckPath[4][1]]" if (stagePath < 4) and 4 < len(deckPath) and swapFirstValue != 4:
$swapSecondValue = 4
"[deckPath[5][1]]" if (stagePath < 5) and 5 < len(deckPath) and swapFirstValue != 5:
$swapSecondValue = 5
"[deckPath[6][1]]" if (stagePath < 6) and 6 < len(deckPath) and swapFirstValue != 6:
$swapSecondValue = 6
"[deckPath[7][1]]" if (stagePath < 7) and 7 < len(deckPath) and swapFirstValue != 7:
$swapSecondValue = 7
"[deckPath[8][1]]" if (stagePath < 8) and 8 < len(deckPath) and swapFirstValue != 8:
$swapSecondValue = 8
"[deckPath[9][1]]" if (stagePath < 9) and 9 < len(deckPath) and swapFirstValue != 9:
$swapFirstValue = 9
"[deckPath[10][1]]" if (stagePath < 10) and 10 < len(deckPath) and swapFirstValue != 10:
$swapFirstValue = 10
"[deckPath[11][1]]" if (stagePath < 11) and 11 < len(deckPath) and swapFirstValue != 10:
$swapFirstValue = 11
Code:
label smartMenu(*items):
python:
# construct a menu
menuitems = []
for i in range(1,len(items)):
menuitems.append((items[i][0],items[i][1]))
menuChoice = renpy.display_menu(menuitems)
return
Code:
$menulist = []
$k=0
while k < len(deckPath):
if stagePath < i:
$menulist.append((deckPath[i][1],i))
$k = k+1
call smartMenu(menulist)
$swapFirstValue = menuChoice