TypeError: %d format: a number is required, not unicode
The game crashes at line 123 which would be:
Code: Select all
"You have %(dmg)d attack."
-I've based my code upon example 2 of this framework http://www.renpy.org/wiki/renpy/doc/coo ... ney_System
-I don't know much about Python or classes, so I've been figuring it out through patterns (in the above framework) and seeing what crashes when I do certain things
-I actually got a full battle system working, but it started crashing when I decided to make more advanced stats (like armor, accuracy, dodge rate, etc) using equations
Question:
So, my question is what exactly is crashing the game? I'm assuming what the error refers to as "unicode" would be when instead of saying, "dmg= 5" I say, "dmg = str*.5" or something (so like, a formula rather than a value). Exactly how do I get the game to display my stats in the dialogue without crashing?
Error:
Code: Select all
I'm sorry, but an uncaught exception occurred.
TypeError: %d format: a number is required, not unicode
While running game code:
- script at line 123 of C:\Program Files\renpy-6.11.0\Current/game/script.rpy
Code: Select all
# You can place the script of your game in this file.
init:
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
$ e = Character('Eileen', color="#c8ffc8")
init python:
#THIS is the player CLASS in which my game CRASHES
class Player:
#def __init__(self, hp=25, mp=10, atk=5):
def __init__(self, end=10, str=10, int=10, dex=10, wdmg=0):
#self.end = end means that self.end is turned into a global value or w/e that can be reffered to outside of player. which kind of matters in a lot of cases.
self.end = end
self.str = str
self.int = int
self.dex = dex
self.wdmg = wdmg
#def update(self, hp, arm, wdmg, dmg, mp, sdmg, acc, dodge, crit): <<--- backup code so I don't have to retype so much (NOT from the time my code actually worked)
def update(self, end, str, int, dex, wdmg):
self.hp = end*10
#I tried the below line after creating the formula in some kind of effort to have a variable that wasn't "unicode." It didn't work.
hp = self.hp
self.arm = end*.25
#This is another example of the above comment
arm = self.arm
self.wdmg = wdmg
self.dmg = str*.5 + wdmg
dmg = 0
self.mp = int*4
mp = self.mp
self.sdmg = int*.7
sdmg = self.sdmg
self.acc = dex*.6
acc = self.acc
self.dodge = dex*.5 + 2
dodge = self.dodge
self.crit = dex*.25
crit = self.crit
#since dmg has an equation invovled in its value it is considered unicode. %()d requires a normal value and cannot use unicode.
[size=85] ##Lines HERE TO##
class Enemy:
def __init__(self, hp=1, mp=1, atk=1):
self.hp = hp
self.mp = mp
self.atk = atk
def update(self, hp, mp, atk):
self.hp = hp
self.mp = mp
self.atk = atk
##HERE PROBABLY have nothing to do with the crash or error (to my understanding)##[/size]
# The game starts here.
label start:
python:
#Classes are reffered to using "ClassName()" without the ""
player = Player()
enemy = Enemy()
$ enemy.update(20,5,3)
#$eatk = enemy.atk
#$ehp = enemy.hp
#$emp = enemy.mp
#$defended =enemy.atk*.8
$ player.update(player.end, player.str, player.int, player.dex, player.wdmg)
#$atk = player.dmg
#$hp = player.hp
#$mp = player.mp
#$heal = player.hp/10
"Now I have %(current_money)d coins."
"You have %(dmg)d attack."
#Crash point ^^^
"You have %(hp)d hit points."
"You have %(mp)d mana points."
"The enemy has %(eatk)d attack."
"The enemy has %(ehp)d hit points."
"The enemy has %(emp)d mana points."
jump Epic_Battle
(2nd question, a bit unrelated):
Is there a way to shorten a line of code (kind of like functions in flash)?
For example:
would it be possible to shorten this:
Code: Select all
menu:
"attack":
$ ehp -= atk
"You strike the enemy for %(atk)d points of damage!"
$ hp -= eatk
"The enemy attacks!"
"You lost %(eatk)d hit points!"
jump hp_check
attack()
^(If I remember correctly, you could do something to that effect in flash).
Thanks for reading.