Dungeon Crawl RPG Framework

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#16 Post by nyaatrap »

The codes of showing background images can be shorten massively using globals().

Code: Select all

            for i in ["left3", "right3", "left2", "right2", "front2", "left1", "right1", "front1"]:
                j=globals()[i]
                try:
                    if j.map[j.y][j.x]=="1":
                        renpy.show(i)
                except: pass

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#17 Post by DapNix »

How would one go through with resetting the hp to full after the battle? I'm making a different game from this and I really need to have the HP back after a fight.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#18 Post by nyaatrap »

Code: Select all

class Actor():
    .......
    def reset(self):
        self.hp = self.max_hp
Define a new function and call is like $player.reset()

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#19 Post by DapNix »

nyaatrap wrote:

Code: Select all

class Actor():
    .......
    def reset(self):
        self.hp = self.max_hp
Define a new function and call is like $player.reset()
Seems nice and all, but when I start the game up it says "reset() takes exactly 2 arguments (1 given)"

I suppose this means that I need to have an "if" statement and an "else" statement, but I haven't the slightest idea where they should go. I'm pretty new to python.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#20 Post by nyaatrap »

It means you defined "reset(argument1, argument2)", but called it like "reset(argument1)" (though, if it's defined as a class attribute, and the argument is "self", this self should be omitted)

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#21 Post by DapNix »

nyaatrap wrote:It means you defined "reset(argument1, argument2)", but called it like "reset(argument1)" (though, if it's defined as a class attribute, and the argument is "self", this self should be omitted)
The thing is, I was trying to make it so that both the HP of myself and my enemy got reset. (in case of losing the battle and having to replay it)
No harm in it now though, I just didn't realize that "self" isn't a viable argument, I just had to type in :

Code: Select all

$ player.reset(enemy) 
for the argument and :

Code: Select all

        def reset(self, target):
            self.hp = self.max_hp
            target.hp = target.max_hp  
for the definition. Thanks alot, now I can progress in my little game. :3

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#22 Post by DapNix »

Is it okay if I keep asking questions here about this battle system? I'm still new to Python scripting so I hope it's alright.

Because I have another question.

How would I do if I wanted to script so that 1 of my abilities would, instead of deal damage, open up other options?
Such as a surrender button, if I press it, I lose.
Or a wait button, if I press it, I wait 1 turn.
Or anything else that might work, such as maybe a "convince" button, that will attempt to start dialogue or something.

I have tried many different ways, such as trying to create a new class, but I just can't get a hold of it.

As stated earlier, I would really appreciate it if I could be allowed to come back here every now and then to ask a few questions if I bump into problems when I'm scripting. Either way, thanks alot for the previous help, would love some more!

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#23 Post by nyaatrap »

It's OK to ask here, though if you think those questions are more general questions, I think better to put them on ren'py Q and A section. I'm reading all topics under "Ren'Py Visual Novel Engine" sub-forum anyway.

And to answer your question, there are various ways to do it. One example is:

Code: Select all

screen command:    
        vbox align (.5,.5):
            for i in player.skills:
                textbutton "[i.name]" action Return (value=i)
            textbutton "Retreat" action Return (value="retreat")

Code: Select all

class actor():
    def command(self, target):
            self.skill = renpy.call_screen("command")
            if self.skill = "retreat":
                 #retreat code here
            else:
                 #skill action code here

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#24 Post by DapNix »

nyaatrap wrote:

Code: Select all

 if self.skill = "retreat": 
Invalid Syntax. :/

Switched retreat out to my own "Surrender", though it didn't work.

Code: Select all

Surrender = Skill("Surrender", 100, 0) 

Code: Select all

        def command(self, target):
            self.skill = renpy.call_screen("command")
            if self.skill = "Surrender":
                jump afterbattle
            else:
                target.skill = renpy.random.choice(target.skills)
                self.attack(self.skill, target)
            if target.hp < 1:
                return
            target.attack(target.skill, self)

Code: Select all

    screen command:    
        vbox align (.05,.9):
            for i in player.skills:
                textbutton "[i.name]" action Return (value=i)
                textbutton "Surrender" action Return (value=Surrender)
These are the involving codes that I have. Been looking at them several times, can't find the problem.

On a side note, since it's okay, I will keep posting problems I get here (problems involving code from that which you have posted here) and if I get other problems, that will be posted on other forums.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#25 Post by nyaatrap »

My mistake. It should be:

Code: Select all

 if self.skill == "retreat":[code]

DapNix
Regular
Posts: 52
Joined: Fri Mar 01, 2013 6:15 am
Contact:

Re: Dungeon crawling RPG frame

#26 Post by DapNix »

This code really isn't liking me one bit..

The previous error dissappeared, but this new one is driving me crazy.

After I got the code to work, I added in

Code: Select all

jump surrender
But for some reason, I get :

jump surrender: Invalid syntax

Why does that invalid syntax keep popping up? Can the jump function not be used inside if-statements?

Since I already have other jump statements, this cannot possibly be an invalid syntax, because otherwise it shouldn't have worked the first time, right?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#27 Post by nyaatrap »

Because you are using ren'py statements inside of a python block. You need to write anything in python. It's renpy.jump() - but it seems it's not written in the document (It somewhat lacks major statements like, say, jump, e.t.c.)

User avatar
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Re: Dungeon crawling RPG frame

#28 Post by Zeroized »

Sorry to necropost, but this seems to be the right place to ask.
I've been using the battle part of this script to generate my own battles, and I'm stuck trying to create status effects.
How can you make status effects, or force your opponent to take a certain action when you do something? For example, you hit them with a "Stun" skill, and your opponent can't attach you the next turn. Or, you use the "Provoke" skill, and your opponent is forced to attack you each turn.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Dungeon crawling RPG frame

#29 Post by nyaatrap »

There are several ways. One example is, add a status attribute on the class, and check them when the command method is called:

Code: Select all

  class Actor(renpy.store.object):
        def __init__(self, name, max_hp=0, skills=[], status=[]):
            self.name=name
            self.max_hp=max_hp
            self.hp=max_hp
            self.skills = skills
            self.status = status
        def command(self, target):
            if "stun" in self.status:
                 self.skill = Pass
            else:
                 self.skill = renpy.call_screen("command")

User avatar
Zeroized
Regular
Posts: 33
Joined: Sat Mar 23, 2013 12:33 am
Contact:

Re: Dungeon crawling RPG frame

#30 Post by Zeroized »

Awesome, someone else with more knowledge of python than me told me to do something like you suggested. I did just that, and it worked wonders. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users