[SOLVED]why renpy give me "Player has no attribute 'statusTruth' "?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

[SOLVED]why renpy give me "Player has no attribute 'statusTruth' "?

#1 Post by leoxhurt »

i have a class "Player" and added a self.statusTruth and self.statusLie in a secondary script, not in the script.rpy, i want to when running the game chance the valor in the "statusTruth" and the "statusLie"

Code: Select all

class Player:
        def __init__( self, name="hero", level=1, modifierLarge=15, modifierSmall=14, statusTruth= 0, statusLie= 0):

            self.name = name
            self.level = level
            self.modA = modifierLarge
            self.modB = modifierSmall
            self.statusTruth =  0
            self.statusLie = 0
            self.modSum = modifierLarge + modifierSmall
            self.XP = 0
            self.HP=0
            self.attack = 0
            self.defense = 0
            self.attackBuff = 0
            self.defenseBuff = 0
            self.maxHP = 0
            self.defending = False
            self.inventory = []
            self.weapon_bonus=0
            
            self.set_stats()
            
and when i try to add something to this, per example:

Code: Select all

    python:
        Player.statusTruth += 1
    $ Player.statusTruth = max(0, min(Player.statusTruth, 5))
then renpy give error that says "Player has no attribute 'statusTruth' " why?
Last edited by leoxhurt on Sun Oct 01, 2017 4:01 pm, edited 1 time in total.

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#2 Post by SuperbowserX »

Can you post the error message (or the traceback)?

leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#3 Post by leoxhurt »

SuperbowserX wrote: Sat Sep 30, 2017 6:30 pm Can you post the error message (or the traceback)?
how i upload a image here? i'm a little newbie at forums so, i will put the code

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 170, in script
    python:
  File "game/script.rpy", line 171, in <module>
    Player.statusTruth += 1
AttributeError: type object 'Player' has no attribute 'statusTruth'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 170, in script
    python:
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 171, in <module>
    Player.statusTruth += 1
AttributeError: type object 'Player' has no attribute 'statusTruth'

Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.4.2187
A Tale of Truths and Lies Demo 1.5

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#4 Post by Divona »

Try assign class to object first?:

Code: Select all

    python:
        player = Player()
        player.statusTruth += 1
Completed:
Image

leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#5 Post by leoxhurt »

Divona wrote: Sat Sep 30, 2017 11:08 pm Try assign class to object first?:

Code: Select all

    python:
        player = Player()
        player.statusTruth += 1
it seems work, but when i try to call a screen that shows "You have [Player.statusTruth] Truth points" "You have [Player.statusLie] Lie points " to show the points, renpy give me this, how i use this method here?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 1472, in script
    call screen aff_screen
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "game/script.rpy", line 1462, in execute
    screen aff_screen:
  File "game/script.rpy", line 1462, in execute
    screen aff_screen:
  File "game/script.rpy", line 1463, in execute
    frame:
  File "game/script.rpy", line 1464, in execute
    has vbox
  File "game/script.rpy", line 1465, in execute
    text "You have [Player.statusTruth] Truth points"
AttributeError: type object 'Player' has no attribute 'statusTruth'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 1472, in script
    call screen aff_screen
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\ast.py", line 1706, in execute
    self.call("execute")
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\ast.py", line 1724, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\statements.py", line 145, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 471, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\exports.py", line 2526, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\ui.py", line 285, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 2538, in interact
    scene_lists.replace_transient()
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 822, in replace_transient
    self.remove(layer, tag)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 1107, in remove
    self.hide_or_replace(layer, remove_index, "hide")
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\core.py", line 1031, in hide_or_replace
    d = oldsle.displayable._hide(now - st, now - at, prefix)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\screen.py", line 443, in _hide
    self.update()
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\display\screen.py", line 578, in update
    self.screen.function(**self.scope)
  File "game/script.rpy", line 1462, in execute
    screen aff_screen:
  File "game/script.rpy", line 1462, in execute
    screen aff_screen:
  File "game/script.rpy", line 1463, in execute
    frame:
  File "game/script.rpy", line 1464, in execute
    has vbox
  File "game/script.rpy", line 1465, in execute
    text "You have [Player.statusTruth] Truth points"
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\text\text.py", line 1328, in __init__
    self.set_text(text, scope, substitute)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\text\text.py", line 1426, in set_text
    i, did_sub = renpy.substitutions.substitute(i, scope, substitute)
  File "D:\Documentos\Games\renpy-6.99.1-sdk\renpy\substitutions.py", line 232, in substitute
    s = formatter.vformat(s, (), kwargs)
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 563, in vformat
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 585, in _vformat
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 652, in get_field
AttributeError: type object 'Player' has no attribute 'statusTruth'

Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.4.2187
A Tale of Truths and Lies Demo 1.5

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#6 Post by Divona »

Code: Select all

  File "game/script.rpy", line 1465, in execute
    text "You have [Player.statusTruth] Truth points"
AttributeError: type object 'Player' has no attribute 'statusTruth'
See the explanation in traceback report? It's the same thing, you don't call class directly in this case. You just have to use the object that you assigned the Player class to.

Code: Select all

    text "You have [player.statusTruth] Truth points.
Completed:
Image

leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#7 Post by leoxhurt »

Divona wrote: Sun Oct 01, 2017 10:50 am

Code: Select all

  File "game/script.rpy", line 1465, in execute
    text "You have [Player.statusTruth] Truth points"
AttributeError: type object 'Player' has no attribute 'statusTruth'
See the explanation in traceback report? It's the same thing, you don't call class directly in this case. You just have to use the object that you assigned the Player class to.

Code: Select all

    text "You have [player.statusTruth] Truth points.
ok the player got a Truth point, but when i see the defense show me 1 result, why?

Code: Select all

def set_stats(self):
            self.maxHP = int(math.pow(self.level, 2) + self.modSum)
            self.HP = int(self.maxHP) # replenishes HP when levelling up
            self.attack = int(self.level * self.modA + self.modSum + self.weapon_bonus + self.statusLie)
            self.defense = int(self.level + self.modB * self.statusTruth)

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#8 Post by Divona »

Code: Select all

    self.defense = int(self.level + self.modB * self.statusTruth)
self.defense = int(1 + 14 * 0)
-- 1 + (14 * 0) = 1
Completed:
Image

leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#9 Post by leoxhurt »

Divona wrote: Sun Oct 01, 2017 11:35 am

Code: Select all

    self.defense = int(self.level + self.modB * self.statusTruth)
self.defense = int(1 + 14 * 0)
-- 1 + (14 * 0) = 1
got, but is not possible to use truth or lie points in this? i will change the valor in-game with:

Code: Select all


 python:
                player = Player()
                player.statusLie += 1
            $ player.statusLie = max(0, min(player.statusLie, 5))
it appeared "you have 1 Truth point" when i used this, but seems the point not recognised, right?

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#10 Post by Divona »

You have to call "player.set_stats()" every time you want stats to be calculated. It's not automatic.

Code: Select all

init python:
    player = Player()

label start:

    "You have [player.defense] points.     # This should show up as 1.

    $ player.Truth += 1
    $ player.set_stats()

    "Now, you have [player.defense] points."    # This should now show up as 15.
Completed:
Image

leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#11 Post by leoxhurt »

Divona wrote: Sun Oct 01, 2017 11:58 am You have to call "player.set_stats()" every time you want stats to be calculated. It's not automatic.

Code: Select all

init python:
    player = Player()

label start:

    "You have [player.defense] points.     # This should show up as 1.

    $ player.Truth += 1
    $ player.set_stats()

    "Now, you have [player.defense] points."    # This should now show up as 15.
ok, is only

Code: Select all

$ player.Truth += 1
$ player.set_stats()
or i need a

Code: Select all

python:
    player = Player()
$ player.statusTruth += 1
$ player.set_stats()
cause in the python way, when i tried to add point a second time, it gives result as 1

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#12 Post by Divona »

You only need to assign Class to object once. So "player = Player()" will reside in "init" phase and never need to be assigned again. If I understand you correctly.
Completed:
Image

leoxhurt
Regular
Posts: 34
Joined: Fri Aug 04, 2017 6:25 pm
Contact:

Re: why renpy give me "Player has no attribute 'statusTruth' "?

#13 Post by leoxhurt »

Divona wrote: Sun Oct 01, 2017 12:37 pm You only need to assign Class to object once. So "player = Player()" will reside in "init" phase and never need to be assigned again. If I understand you correctly.
ok worked, really really thanks for the help

Post Reply

Who is online

Users browsing this forum: Bing [Bot]