That explains a lot, though I find it confusing that variables behave in different ways.
Back to my initial problem:
This is strange. I watched the variable lastspell through the console when something didn't work, and this happened:
Code: Select all
def cast_spell(self, sp):
global lastspell
self.setactivecharacter(1 - self.activecharacter)
lastspell = sp.name
renpy.restart_interaction()
def setactivecharacter(self, char):
if char != self.activecharacter:
renpy.hide_screen('mainparty_spells')
self.activecharacter = char
renpy.show_screen('mainparty_spells', self)
This changes
lastspell properly.
Code: Select all
def cast_spell(self, sp)
global lastspell
self.setactivecharacter(1 - self.activecharacter)
lastspell = sp.name
renpy.restart_interaction()
def setactivecharacter(self, char):
if char != self.activecharacter:
renpy.call('switcheroo', self, char)
label switcheroo (bat, char):
hide screen mainparty_spells
pause 0.3
$ bat.activecharacter = char
show screen mainparty_spells(bat)
return
This doesn NOT change
lastspell when cast_spell is called!
I've come to a point where this is really annoying. I will go into detail a little more.
TL;DR:
I'm doing all this while in a call for an empty screen so I have a pseudo-loop that waits for something, so I can't call anything else without the "switcheroo" trick, but it messes up variables I change during switcheroo. call_in_new_context on the other hand messes up the visuals.
Long explanation:
I'm making a battle engine aka minigame that involves status screens (no problem) and called screens that wait for a specific input from the player (problem, see below).
To keep the script from advancing until the combat is over, I use:
Code: Select all
screen battleround:
zorder 1
label combatstart:
while True: # <-- because "switcheroo" makes "battleround" close
call screen battleround
I have to do it this way because
Code: Select all
label combatstart:
while True:
jump combatstart
hangs the game. This unfortunately means that I can't call anything else (create a new interaction) without call_in_new_context, which would screw up my screen, and that even includes renpy.pause because apparently that creates a new interaction. Through trial-and-error, I found out that if I call a label from within a function, I CAN use pause and screen calls,
BUT any variables I change during the label call remain unchanged, probably because this label call somehow creates a new (pseudo?)context.
So I either need a way to keep my script from advancing without resorting to calling an empty screen (HIGHLY preferred), or another way to make a call from within the call that doesn't affect variable interaction.
EDIT:
Code: Select all
def cast_spell(self, sp):
effectbuffer = sp.effects
for i in range(len(effectbuffer)):
currenteffect = effectbuffer[i]
if currenteffect[0] == 0:
self.directdamagespell(currenteffect[1], currenteffect[2], currenteffect[3])
if currenteffect[0] == 4:
self.change_mana(currenteffect[1], currenteffect[2], currenteffect[3], currenteffect[4])
self.kill_selectedballs()
self.update_pool(-1, 0)
self.setactivecharacter(1 - self.activecharacter)
renpy.restart_interaction()
def directdamagespell(self, type, amount, target):
if target == 1:
renpy.call('gettarget', self, 0)
global aa
aa = _return
selectedtarget = _return
selectedtarget.takehit(type, amount)
renpy.restart_interaction()
label gettarget(bat, party):
call screen selectcharacter(bat, 0)
return _return
Usually, when called from the script without any tricks, the screen
selectcharacter works fine; watched variables changed their value properly so the problem is not there.
But not only did
aa (a control variable for bugtesting) not change value, but anything after "elf.directdamagespell(currenteffect[1], currenteffect[2], currenteffect[3])" in
cast_spell(self, sp) was not executed; the whole
Code: Select all
self.kill_selectedballs()
self.update_pool(-1, 0)
self.setactivecharacter(1 - self.activecharacter)
renpy.restart_interaction()
that works fine if "currenteffect[0] == 4" is ignored. It probably has also to do with calling the label because I don't call a label in
self.change_mana.
Tell me if I should take this to a new thread because it's more of a "how do I do this" instead of a "why does this happen".