The weird thing that's happening is that when I open the developer console, some variables seem to change.
(you can run this code without any images and see it work).
Basically, every turn each player controlled dude gets to choose an attack, then each ai controlled dude gets to choose an attack(which are still controlled by player for testing purposes).
active_char tracks who's turn it is. dudeslist is a list of all characters and the active_char is the index of the character who's turn it is.
Perhaps superfluously, active_dude also points directly to the dude class who's turn it currently is.
Now if you run this code, you can click an attack, it will do the attack, and it will cycle to the next dude, exactly as it should.
But somehow, if you open the developer console, it always reverts back to the very first character in dudeslist. Does that happen because of the line "$ active_char = 0"? Why would it run that again, simply when I open the developer console?
You can test it out. Be sure to click an attack first. Then press shift+O and you see the name change instantly. I can't figure this one out.
Code: Select all
label start:
scene bg background
init python:
import random
import copy
$ active_char = 0 #Whose turn is it? Active char
define ai_list = {1 : "defensive", 2 : "offensive", 3 : "tactical"}
init python:
def update_char():
global active_char
active_char += 1
if active_char > (len(dudeslist) -1):
active_char = 0
active_dude = dudeslist[active_char]
# print "active char = " + str(active_char)
class Attack(object):
def __init__(self, name = "Unnamed attack", damage = 0, cha_multiplier = 1, dex_multiplier = 1, int_multiplier = 1, chu_multiplier = 1, special = False):
self.name = name
self.damage = damage
self.cha_multiplier = cha_multiplier
self.dex_multiplier = dex_multiplier
self.int_multiplier = int_multiplier
self.chu_multiplier = chu_multiplier
self.special = special
class Dude_Class(object):
def __init__(self, attack1, attack2, attack3):
self.attack1 = attack1
self.attack2 = attack2
self.attack3 = attack3
class Dude(object):
def __init__(self, name = "unnamed", control = "AI" , role="melee", xaxis=0, yaxis=0):
self.name = name
self.role = role
self.control = control #player or AI
self.x = xaxis
self.y = yaxis
self.ainumber = 1
self.speed = 3
self.range = 1
self.update_dude_class()
def rotate_ai(self):
self.ainumber += 1
if self.ainumber > (len(ai_list)-1):
self.ainumber = 0
self.ai = ai_list[self.ainumber]
self.update_ai()
def update_ai(self):
self.ai = ai_list[self.ainumber]
def move(self):
#temporary move test
self.x = self.x + 1
self.y = self.y + 1
def update_dude_class(self):
#temp class decider
self.dudeclass = Dude_Class(
Attack("Recite poetry", 10, cha_multiplier= 1.5),
Attack("Wink", 4, int_multiplier= 3),
Attack("Flee", 0)
)
python:
dudeslist = []
player_dudeslist = []
AI_dudeslist = []
player_dudeslist.append(Dude("Chosen", "player", "melee", 1, 1))
player_dudeslist.append(Dude("Friend", "player", "melee", 0, 2))
AI_dudeslist.append(Dude("Paramour", "AI", "melee", 5, 2))
AI_dudeslist.append(Dude("Rival", "AI", "melee", 5, 4))
dudeslist = player_dudeslist + AI_dudeslist
active_dude = dudeslist[active_char]
screen MoveAI():
frame:
xpos 300 ypos 300
button:
action Function(active_dude.move)
text _("Move automatically") style "button_text"
screen Continue():
frame:
xpos 400 ypos 400
button:
action Return()
text _("Continue") style "button_text"
screen ChooseAttack():
vbox:
xpos 400 ypos 40
text "{}'s turn".format(dudeslist[active_char].name)
button:
action [Function(update_char), Notify("You chose {} attack for {} damage".format(dudeslist[active_char].dudeclass.attack1.name, dudeslist[active_char].dudeclass.attack1.damage))]
text "> {}".format(dudeslist[active_char].dudeclass.attack1.name)
button:
action [Function(update_char), Notify("You chose {} attack for {} damage".format(dudeslist[active_char].dudeclass.attack2.name, dudeslist[active_char].dudeclass.attack2.damage))]
text "> {}".format(dudeslist[active_char].dudeclass.attack2.name)
button:
action [Function(update_char), Notify("You chose {} attack for {} damage".format(dudeslist[active_char].dudeclass.attack3.name, dudeslist[active_char].dudeclass.attack3.damage))]
text "> {}".format(dudeslist[active_char].dudeclass.attack3.name)
show screen ChooseAttack()
show screen MoveAI()
call screen Continue()