Calling attacks from screen buttons, now with error report!

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.
Message
Author
squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#16 Post by squark »

Please, someone. Anyone, I'm getting a little desperate.
I'm getting this now:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/skill.rpy", line 175, in script
        python:
  File "game/skill.rpy", line 176, in python
            test.Specials(pointy)
AttributeError: Battle instance has no attribute 'Specials'

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

Full traceback:
  File "C:\Games\Dev\renpy\renpy\execution.py", line 261, in run
  File "C:\Games\Dev\renpy\renpy\ast.py", line 630, in execute
  File "C:\Games\Dev\renpy\renpy\python.py", line 978, in py_exec_bytecode
  File "game/skill.rpy", line 176, in <module>
AttributeError: Battle instance has no attribute 'Specials'

Windows-post2008Server-6.1.7601-SP1
Ren'Py 6.13.7.1646
So, fine, I add this line to Class Battle:

Code: Select all

Specials = ([pointy(), doom(), seedy(), healing(), gambler(), mustard(), sparrow(), shadows()])
They're all set up as def blocks in the skill.rpy file.

Then it throws this at me:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 12, in script
        python:
  File "game/script.rpy", line 22, in python
            test = Battle(phi, [Rat("Obligatory Rat"), Rat("Test Rat")])
  File "game/enviroment.rpy", line 28, in python
                Specials = ([pointy(), doom(), seedy(), healing(), gambler(), mustard(), sparrow(), shadows()])
NameError: global name 'pointy' is not defined

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

Full traceback:
  File "C:\Games\Dev\renpy\renpy\execution.py", line 261, in run
  File "C:\Games\Dev\renpy\renpy\ast.py", line 630, in execute
  File "C:\Games\Dev\renpy\renpy\python.py", line 978, in py_exec_bytecode
  File "game/script.rpy", line 22, in <module>
  File "game/enviroment.rpy", line 28, in __init__
NameError: global name 'pointy' is not defined

Windows-post2008Server-6.1.7601-SP1
Ren'Py 6.13.7.1646
And this is the seemingly offending def block:

Code: Select all

nit python:
    class Skills(Battle):
    #... other stuff
                def pointy():
            renpy.call_screen("targetChoice")
            if swNov:
                Enemy.life_temp -= 10
            elif swApp:
                Enemy.life_temp -= 15
            elif swJo:
                Enemy.life_temp -= 25
            elif swEx:
                Enemy.life_temp -= 50
            elif swMa:
                Enemy.life_temp -= 75
            else:
                Enemy.life_temp -= 100
            # swNov, swApp, swJo, swEx, swMa and that last one are flags set up in the script.rpy file.
The user clicks the button to select the attack, which initiates a jump to the label "stabby" (below) which then calls the above block.

Code: Select all

label stabby:
    python:
        test.Specials(pointy)
All of the special attacks are defined under Class Specials, which is defined at the same level as Skills (the main calculator for the entire sordid affair).

So, can anyone tell me what's going wrong?
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#17 Post by squark »

Sorry to double like this, but I really am losing it now.
I need someone to do this part of it for me.
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#18 Post by xela »

squark wrote:Sorry to double like this, but I really am losing it now.
I need someone to do this part of it for me.

Which part? Just post last version of your code and try to explain what you need it to do exactly...


==================================
After taking a quick look at your code:
I cannot see a quick fix here. You need to rewrite Skills class as a function or split it and write those attacks as methods of Characters class for example so you can target properly.

Idea with jumping labels is insane by the way, no matter how you look at it :)
Like what we're doing? Support us at:
Image

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#19 Post by squark »

xela wrote:Which part?
The Battle special skills.

I had a few errors, so I went back to a (more or less) clean, unaltered version a few days ago. I'll post that up as soon as I get home.

Well, I knew a quick fix wouldn't be on the cards, and rewriting the entire Skills class to incorpate methods is something I'll look at. It did hit me that because the rest of the system is python, the whole damn thing should be python.
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#20 Post by squark »

Doublepost again, I know.
Here's the system as it currently stands.
It doesn't freeze, or lock or blot the screen out for some reason (as it used to do at one point).
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#21 Post by squark »

Okay, I still haven't had any success (not for lack of trying), and I think I've narrowed it down to one section.

Code: Select all

    screen attackChoice:
        modal True
        frame:
            xalign 0.5 yalign 0.95
            vbox:
                textbutton "Sword" action (Show("targetChoice", env=env), Hide("attackChoice"))
                textbutton "Doom of Darkness" action Show("targetChoice", env=env)
                textbutton "Cast Into The Shadows" action Show("targetChoice", env=env) 
                textbutton "Sparrow of The Wind" action Show("targetChoice", env=env)
        frame:    
            xalign 0.85 yalign 0.95
            vbox:    
                textbutton "Evening Muster" action Show("targetChoice", env=env)
                textbutton "HOPE it all" action Show("targetChoice", env=env)
                textbutton "Cancel" action Hide("attackChoice")                           
        
    screen targetChoice:
        modal True
        frame:
            xalign 0.5 yalign 0.5
            vbox:
                for entry in env.enemies:
                    textbutton entry.name action (Hide("targetChoice"),Return([Basic_Attack(env.char, [entry], env)])) size_group "target"
                textbutton "Cancel" action Hide("targetChoice") size_group "target"
In particular, the "for entry in env.enemies" piece. I know I've got to set up seperate defs for them to work, that's not the problem. The problem is, how do actually call them from the buttons? I'm not really clear on how it actually works.
I've heard the whole skill.rpy will need changing, but I will need someone to help with this part of it. The deadline is looming and I can't do this by myself.
I've tried everything so far -and while some of them do seem like they should work- and it returns an error. When I think I'm getting somewhere, Ren'Py just doesn't seem to like it.

Also, I've been trying to hand an award at the end of the fight (key item, story important).
So, I did this:

Code: Select all

   python:
      # other stuff, this works
      frag = True <-- this was set up for later, so it wouldn't think I'm trying to do something I haven't defined
      # other stuff, also works
Now, the item I'm trying to add is this:

Code: Select all

    class JarFrag(Item):
        def __init__(self):
            Item.__init__(self)
            self.ide = "fragment"
            self.kat = "Valuables"
            self.name = "Fragment of a strange jar"
Every other item the player starts with is defined in the exact same way, and they work.
After the battle, I try to add it with this:

Code: Select all

            if frag:
                phi.inventory.addItem([JarFrag(),1])
                self.itemNote = ("Phi recovered a fragment of a strange jar!")            
            else:
                pass
The important piece seems to be this:

Code: Select all

        def addItem(self, pItem, pQuant=1):
            if not (pItem.kat in self.list): # If the Inventory has never encountered this category before, create it.
                self.list[pItem.kat] = [[pItem,pQuant]]
                return
            for entry in self.list[pItem.kat]: # Try to find the item class in the Inventory
                if entry[0].ide == pItem.ide:
                    entry[1] = min(self.singlemax, entry[1] + pQuant)
                    return
            self.list[pItem.kat].append([pItem,pQuant])
            #self.sort(kat)
            
        def addItemlist(self, pList):
            for item in pList:
                self.addItem(item[0],item[1])
                
        def removeItem(self, pItem, pQuantity):
And here's what it spews at me:
Traceback wrote: I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script.rpy", line 38, in script
python:
File "game/script.rpy", line 41, in python
ybt2.preparationPhase()
File "game/enviroment.rpy", line 42, in python
self.executionPhase() # After all actions are set, move on to the next phase
File "game/enviroment.rpy", line 54, in python
self.cleanupPhase()
File "game/enviroment.rpy", line 68, in python
self.preparationPhase()
File "game/enviroment.rpy", line 42, in python
self.executionPhase() # After all actions are set, move on to the next phase
File "game/enviroment.rpy", line 54, in python
self.cleanupPhase()
File "game/enviroment.rpy", line 70, in python
self.win()
File "game/enviroment.rpy", line 98, in python
phi.inventory.addItem([JarFrag(),1])
File "game/inventory.rpy", line 13, in python
if not (pItem.kat in self.list): # If the Inventory has never encountered this category before, create it.
AttributeError: 'RevertableList' object has no attribute 'kat'

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

Full traceback:
File "C:\Games\Dev\renpy\renpy\execution.py", line 261, in run
File "C:\Games\Dev\renpy\renpy\ast.py", line 630, in execute
File "C:\Games\Dev\renpy\renpy\python.py", line 978, in py_exec_bytecode
File "game/script.rpy", line 41, in <module>
File "game/enviroment.rpy", line 42, in preparationPhase
File "game/enviroment.rpy", line 54, in executionPhase
File "game/enviroment.rpy", line 68, in cleanupPhase
File "game/enviroment.rpy", line 42, in preparationPhase
File "game/enviroment.rpy", line 54, in executionPhase
File "game/enviroment.rpy", line 70, in cleanupPhase
File "game/enviroment.rpy", line 98, in win
File "game/inventory.rpy", line 13, in addItem
AttributeError: 'RevertableList' object has no attribute 'kat'

Windows-post2008Server-6.1.7601-SP1
Ren'Py 6.13.7.1646
It's the only freaking thing that seems to have a particular problem with "kat". After all, in script.rpy there's a a few lines adding starting items to the player, and each one of those items is defined the exact same way as JarFrag. So, I don't get it.
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#22 Post by squark »

Me again, I've had an idea. I've made up my mind to go the python route on this (makes sense, I need it flexible) but I need clarification on a couple of things.
If I have this set up:

Code: Select all

   python:
      #other stuff
      def stab(variables)
         #other stuff related to stab
and I want it called like this:

Code: Select all

   screen swordSkills:
      textbutton "stab" action #and here's where I have no idea what to do
As it says, I have no idea which action to use for invoking the calculations in stab().
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#23 Post by xela »

Are you still on this?

Or is it to late to take a look at your code?
Like what we're doing? Support us at:
Image

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#24 Post by squark »

It's never too late, as I'll using a perfected script for a couple more projects I have planned.
I was losing hope for a reply from anyone (and I do realise that people have lives of their own to lead)
Anyway, I'll upload the whole thing as it stands. It mightn't load properly, I was wiped last night when I edited it.
I have the inventory error figured out, so I just need help with the special attacks (still).

Just finished now. Here you go

Gah! Stupid Firefox is telling that "realise" spelled with an S instead of a Z is wrong!
Oh well. They're both right, but neither is wrong.

Thanks again!
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#25 Post by kankan »

The code you posted for specials is different than that of the zip, right? I'm not seeing the offending lines from before in the files, so it's hard to see what went wrong. My guess (??) was that you had pointy() defined within the Skill class (which would make sense). Skill was an extension of Battle at the time, but Battle couldn't see the code within Skill (hence the "pointy is not defined" thing) since it's a one-way relationship (Skill is-a Battle, but Battle is-not-a Skill). By the way, you should probably avoid using inheritance for things that are not subcategories because it gets confusing rather quickly (Skill probably isn't a Battle...).

Judging from what you were saying though, you wanted it to actually jump to a label named stabby that would call pointy...? I'm not exactly sure what was going on, so my guesses might be way off the mark.

squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: Calling attacks from screen buttons, now with error repo

#26 Post by squark »

The above post is the most current version, and I'm not using Jump actions. If I can wrap my head around this soon, I'll be well able to make things as awesome out there as they are in my head >.<

What you've said makes perfect sense, though. I'm still fairly new to python structuring, but getting there. So if I shouldn't have it defined within (and inheriting from) Skill, it sounds like making a class just for pointy() - while this is most likely not right, and even ludicrous - seems like a solution at this time (I'm technically still waking up :P).

What I'm understanding is use this:

Code: Select all

#yadda yadda
   Skill = Battle(Skill1(), Skill2(), etc(), etc())
And use seperate classes to define each of them?
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#27 Post by kankan »

Actually, since Pointy is-a Skill, it's fine to inherit from Skill! The beginners' rule for inheritance (which gets a lot trickier as you move on) is that if a class is-a subcategory of another class (Dog is-a Animal, Rose is-a Flower), then using inheritance is okay. If a class contains another class by use (Human has-a Hand, Pen has-a Ink), then inheritance usually is a bad idea, and it's probably better to stuff an instance of the contained class into the main class (human.hand = Hand()).

I'm not sure where you're going with having a skill equal a battle with skills... It sounds like you're building in a loop which is bad; if you have to create an instance of Skill, it makes an instance of Battle, which uses instances of Skills. I would say to keep Battle and Skill as completely separate classes, where Battle keeps track of events in a battle where Skill is the class for things usable in a battle. What's more likely is to have your Character class have a field inside of it containing a list of the skills that character can use (Character has-a Skill).

EDIT: Ohh, I see. Defining something inside of a class does not mean it inherits from that class. It is either a "nested class" or a "method" of that class. Say I have a class named Skill:

Code: Select all

class Skill(object):
    def __init__(self, damage): #and some other stuff
        self.damage = damage

    def use_skill(self, target):
        target.HP -= self.damage

    class Inner:
        #stuff
So the main class is Skill, which has a method named use_skill and a nested class named Inner. Inner and use_skill are invisible to everything outside of Skill unless you're using an instance of skill:

Code: Select all

## Outside of Skill ##
use_skill(enemy1)  #ERROR
newIn = Inner()  #ERROR

skill = Skill(20)
skill.use_skill(enemy1)  # This is fine.
inner = skill.Inner()  # This should also be fine.
Those are fine and dandy, but what you really want in this case is inheritance of skills, not nested classes (or methods for each skill, which is what it sounds like might've been happening). Inheritance looks more like this:

Code: Select all

class Skill(object):
    def __init__(self, damage):
        self.damage = damage

    def do_damage(self, target):
        target.HP -= self.damage

    def specialEffect(self, target):
        return    # No special effect; does nothing

    # Other stuff

class PoisonSting(Skill):
    def specialEffect(self, target):
        # Poison the target

class ThunderWave(Skill):
    def specialEffect(self, target):
        # Paralyze the target
So now we have three classes, one Skill class and two classes that extend it. Now let's try this out:

Code: Select all

normalSkill = Skill(20)
poisonSkill = PoisonSting(20)
thunderSkill = ThunderWave(20)

normalSkill.do_damage(enemy1)    # Enemy1 loses 20 HP
normalSkill.specialEffect(enemy1)    # Does nothing; normal attacks don't have special effects!

poisonSkill.do_damage(enemy2)    # Enemy2 loses 20 HP
poisonSkill.specialEffect(enemy2)    # Poisons enemy2

thunderSkill.do_damage(enemy3)    # Enemy3 loses 20 HP
thunderSkill.specialEffect(enemy3)    # Paralyzes enemy3
So what happened? The poisonSkill and thunderSkill both do damage according to their parent class's method; they get to keep methods their parent uses as long as they don't override them. But what happened with specialEffect? The Skill class has the base method: it does absolutely nothing. But poisonSkill does something different from thunderSkill! That's because each has their own method defined for it; they override Skill's specialEffect() with their own versions. Inheritance is for cases like this, where you have cases that extend functionality for a generic main category.
Last edited by kankan on Mon Apr 08, 2013 7:19 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#28 Post by xela »

kankan wrote:

Code: Select all

class Skill:
    def __init__(self, damage):
        self.damage = damage

    def do_damage(self, target):
        target.HP -= self.damage

    def specialEffect(self, target):
        return    # No special effect; does nothing

    # Other stuff

class PoisonSting(Skill):
    def specialEffect(self, target):
        # Poison the target

class ThunderWave(Skill):
    def specialEffect(self, target):
        # Paralyze the target
So now we have three classes, one Skill class and two classes that extend it. Now let's try this out:

Code: Select all

normalSkill = Skill(20)
poisonSkill = PoisonSting(20)
thunderSkill = ThunderWave(20)

normalSkill.do_damage(enemy1)    # Enemy1 loses 20 HP
normalSkill.specialEffect(enemy1)    # Does nothing; normal attacks don't have special effects!

poisonSkill.do_damage(enemy2)    # Enemy2 loses 20 HP
poisonSkill.specialEffect(enemy2)    # Poisons enemy2

thunderSkill.do_damage(enemy3)    # Enemy3 loses 20 HP
thunderSkill.specialEffect(enemy3)    # Paralyzes enemy3
Why are you using oldstyle classes by the way? Have the master class inherit from object, it just makes sense to do so.

This is the best approach. Skills are disabled now and I don't want to dig in the code on how to enable them but the above approach is prolly the best if you want to use inheritance (I usually tend to avoid that if I can help it).

Main problem with your old setup is that you didn't actually aim skills at anything and got errors instead, looks like you're on the right track now.
Like what we're doing? Support us at:
Image

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#29 Post by apricotorange »

Edit: nevrmind, accidentally posted to wrong thread.

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Calling attacks from screen buttons, now with error repo

#30 Post by kankan »

I totally forgot about the new versus old-style classes actually, oops. It wasn't exactly an emphasized topic for our class since the differences aren't that noticeable, but it's screwed me over more than once while using Ren'py. I'll fix that, thanks!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]