Code: Select all
label do_zone:
python:
# Sprite Lists
manager = SpriteManager(update=tiles_update, event=tiles_event)
# Retain Data and Prevent Rollback for this Interaction
renpy.block_rollback()
renpy.retain_after_load()
# Set Grid Running Status
ev_grid_running = True
safeguard = False
# Show the Screens
renpy.show_screen("town_bg")
renpy.show_screen("town_ui", _layer="town_UI")
renpy.show("testname", layer="events", what=manager)
#renpy.show_screen("debug", _layer="town_UI")
# Run the Interaction System
result = ui.interact()
if result: #<-- Never runs
"Done!" #<-- Never runs
jump map_scrn #<-- Never runs
This is what initiates the UDD.
Code: Select all
def tiles_event(ev, x, y, st):
if store.safeguard:
end_event()
#renpy.end_interaction(True) <-- not working, takes back to Start Game.
return
if ev.type == MOUSEBUTTONDOWN: # Trigger: Pressed click
if ev.button == 1: # Left Click
if store.ev_grid_running:
renpy.restart_interaction()
return
else:
#renpy.end_interaction(True) <-- not working either, takes back to Start Game.
return
elif ev.type == MOUSEBUTTONUP: # Trigger: Let go of click
if ev.button == 1: # Left Click
if store.ev_grid_running:
renpy.restart_interaction()
def tiles_update(st):
if not store.ev_grid_running:
if safeguard:
end_event()
#renpy.end_interaction(True) <-- not working, takes back to Start Game.
return
for tile in tiles[:]:
tile.update()
for char in allies[:]:
char.update()
for wall in walls[:]:
wall.update()
for building in buildings[:]:
building.update()
for dec in decor[:]:
dec.update()
for npc in npcs[:]:
npc.update()
return 0.02
def end_event():
if allies:
for ally in allies[:]:
ally.show.destroy()
allies.remove(ally)
for wall in walls[:]:
wall.show.destroy()
walls.remove(wall)
for tile in tiles[:]:
tile.show.destroy()
tiles.remove(tile)
for building in buildings[:]:
building.show.destroy()
buildings.remove(building)
for dec in decor[:]:
dec.show.destroy()
decor.remove(dec)
for npc in npcs[:]:
npc.show.destroy()
npcs.remove(npc)
store.safeguard = True
The events of the SpriteManager.
I use a separate screen (town_ui on townUI layer) to jump to this label where ev_grid_running is set to False:
Code: Select all
# LABEL : Transition screen for switching to Zone.
label go_town_zone:
if on_exit == "map":
$ disp.screen = "map"
$ ev_grid_running = False
$ renpy.hide_screen("town_ui", layer="town_UI")
$ renpy.hide_screen("testname", layer="town_UI")
$ on_exit = False
$ safeguard = True
scene bg black with fade
jump map_scrn
else:
if disp.screen == "map":
$ disp.screen = "town"
$ safeguard = False
$ event_msgs = []
else:
$ renpy.hide_screen("town_ui", layer="town_UI")
$ renpy.hide_screen("testname", layer="town_UI")
$ safeguard = True
$ on_exit = False
scene bg black with fade
jump do_zone
##############################################################################
# Town Zones
#
# These are the screens used for town zones, background and overlay.
#
screen town_bg:
add current_zone_bg
screen town_ui:
if event_msgs:
style_group "townStyle"
add "talk_bubble.png" align (0.90,0.18)
vbox:
text "[ev_msg]"
elif on_exit:
$ tstr = "World Map" if on_exit == "map" else on_exit
frame:
style_group "townUIbot"
vbox:
text "To: [tstr]"
textbutton _("Next Zone") action [
SetVariable("current_zone",on_exit),
Hide("town_bg"),
Hide("debug"),
Jump("go_town_zone")
]
When ev_grid_running is False, the tiles_event should end_event() and then run end_interaction(True).
However, when renpy.end_interaction(True) runs, it takes me to Start Game menu.
Code: Select all
if result: #<-- Never runs
"Done!" #<-- Never runs
jump map_scrn #<-- Never runs
This never runs.
Right now, my method works. Namely:
1) keeping end_interactions commented, as displayed above
2) keeping these events doing just "return" when safeguard == True.
I need to know how to "close" UDD / SpriteManager.
Outside of perfect programmer terminology. The spirit of this statement is the message I need to convey.
I need to know how to close a SpriteManager.
Not simply Destroy Sprites, and Hide it.
end_interaction isn't doing that. It's closing everything and sending me to Start Game menu.
Is there something else, something simple, something elegant, perhaps Pythonic, where I can just do manager.end()?
I need to optimize my code, and this would be extremely convenient rather than all of the safeguards.
I went through the source to see how Ren'Py knows what screens / displayables are on what layer and how it identifies them, but honestly it was not very explicit to me at all.
I mean, I could not figure out how Ren'Py distinguishes a ui.interact (interaction).
To me, Ren'Py thinks that the interaction is the Game itself, as if it does not know that SpriteManager is the current interaction.
As if it loses track of the interaction's identifier somehow, possibly from my interaction with buttons on other screens? Or from calling scene?
This is the problem that I have identified.
I hope these code snippets make evident what I am trying to achieve and perhaps help clarify what I may be doing that Ren'Py does not like very much.
Please let me know if I need to provide any further information or if anything remains unclear.
Essentially, I need a concrete method (example) to close and repoen SpriteManager that allows me to use other screens as well.
This method seems to leave events / update running, as the sprites are just being destroyed and the displayable hidden.