- Sep 12, 2021
- 510
- 756
Hello, I've coded a very simple card game in Renpy to test it while the team coder works in Unity.
Everything works fine, except that I want to give the player a message if he plays a card without the required prerequisites. Unfortunately, that happens from a function in a python block. Said function is launched from a called screen (and not a shown screen).
So far:
- Adding a displayable like a textbutton is just plain not allowed.
- Renpy.say doesn't work because the resulting message is covered by the elements in the screen.
- Calling a new screen doesn't work because the function is called from a called screen, and the new screen needs to be called in a new context because "interaction in the middle of an interaction".
- Calling in a new context doesn't work because it doesn't have a mean to pass the text to the new screen. I tried to create a different screen for each different message, but it still doesn't work because the function can't find the screen label ("name not defined").
- Setting a variable, putting the message in it and then displaying it in a text-box in the original screen when the function has been closed sounds a good idea but I've cluttered all the screen and have no place where to put this text. Not tested.
I've run out of ideas. Some suggestions?
init block:
game block:
(I tried moving the offending function to the game block but it didn't help).
Everything works fine, except that I want to give the player a message if he plays a card without the required prerequisites. Unfortunately, that happens from a function in a python block. Said function is launched from a called screen (and not a shown screen).
So far:
- Adding a displayable like a textbutton is just plain not allowed.
- Renpy.say doesn't work because the resulting message is covered by the elements in the screen.
- Calling a new screen doesn't work because the function is called from a called screen, and the new screen needs to be called in a new context because "interaction in the middle of an interaction".
- Calling in a new context doesn't work because it doesn't have a mean to pass the text to the new screen. I tried to create a different screen for each different message, but it still doesn't work because the function can't find the screen label ("name not defined").
- Setting a variable, putting the message in it and then displaying it in a text-box in the original screen when the function has been closed sounds a good idea but I've cluttered all the screen and have no place where to put this text. Not tested.
I've run out of ideas. Some suggestions?
init block:
Python:
init python:
<other needed classes>
# Option Cards
class Option( renpy.python.RevertableObject ):
def __init__( self, face, element, cost, prereq_train, prereq_rank, effect, description ):
# Face: image
self.face = face
# Element: Fire, Earth, Air, Water, Neutral
self.element = element
# Cost
self.cost = cost
# Needed Training: Fighter, Scout, Diplomat
self.prereq_train = prereq_train
self.prereq_rank = prereq_rank
# Effect: code to call when playing the card.
self.effect = effect
self.description = description
player_deck = []
def Play_Card ():
global shown_card
<other needed global variables>
# checking prerequisites
if (option_deck[shown_card].prereq_train == "Fighter" and pr_fighter >= option_deck[shown_card].prereq_rank) or (option_deck[shown_card].prereq_train == "Scour" and pr_scout >= option_deck[shown_card].prereq_rank) or (option_deck[shown_card].prereq_train == "Diplomat" and pr_diplomat >= option_deck[shown_card].prereq_rank):
# checking elemental affinity
if ( option_deck[shown_card].element == "Fire" and aff_fire >= option_deck[shown_card].cost ) or (option_deck[shown_card].element == "Earth" and aff_earth >= option_deck[shown_card].cost) or (option_deck[shown_card].element == "Air" and aff_air >= option_deck[shown_card].cost) or (option_deck[shown_card].element == "Water" and aff_water >= option_deck[shown_card].cost):
# paying cost
if option_deck[shown_card].element == "Fire":
aff_fire -= option_deck[shown_card].cost
elif option_deck[shown_card].element == "Earth":
aff_earth -= option_deck[shown_card].cost
elif option_deck[shown_card].element == "Air":
aff_air -= option_deck[shown_card].cost
elif option_deck[shown_card].element == "Water":
aff_water -= option_deck[shown_card].cost
else:
renpy.show_display_say(None,"This shouldn't be happening")
# calling card effects
eval (option_deck[shown_card].effect)
player_play.append( option_deck[shown_card] )
option_deck.pop ( shown_card )
shown_card -= 1
else:
renpy.invoke_in_new_context(notify,"You don't have enough Elemental Affinity to play this card.")
else:
renpy.invoke_in_new_context(notify,"You don't meet the prerequisites to play this card.")
game block:
Python:
screen card_battle():
#stuff happens here#
imagebutton idle option_deck[shown_card].face xpos 1614 ypos 440 action Function( Play_Card )
#other stuff#
textbutton "Commit" xpos 1653 ypos 910 action Return()
(I tried moving the offending function to the game block but it didn't help).