[SOLVED] 2 Functions Interact With Each Other Question?

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
Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

[SOLVED] 2 Functions Interact With Each Other Question?

#1 Post by Nero »

Got question with Function interacting with each other (im lacking little bit on python knowledge for this one)


I made a simple skill that decreases enemy attack damage by 20%. Main focus here is DEBUFFED_DAMAGE_HOLDER now when damage is reduced it will be stored in there.

Code: Select all

    def DAMAGE_DEBUFF_SKILL_PLAYER(self, enemy): # Basic debuff skill
        enemy.DMG_DEBUFF_DURATION = 2
        DEBUFFED_DAMAGE_HOLDER = 0
        DEBUFFED_DAMAGE_HOLDER += 20 * enemy.PLAYER_DAMAGE / 100 # Decrease enemy dmg by 20%
        enemy.PLAYER_DAMAGE -= DEBUFFED_DAMAGE_HOLDER # Remember the reduced damage  

Now that damage is stored in there how do I access it in another function "COOLDOWNS_CHECK(self):" to sum it up again? I know there is a way if I add it a Class but is there way around it?

Code: Select all

    def COOLDOWNS_CHECK(self): # Checks if player is debuffed and decreases the CD
        if self.DMG_DEBUFF_DURATION > 0:
            self.DMG_DEBUFF_DURATION -= 1
            if self.DMG_DEBUFF_DURATION < 1:
                self.PLAYER_DAMAGE += DEBUFFED_DAMAGE_HOLDER
Last edited by Nero on Wed Aug 16, 2017 6:29 pm, edited 1 time in total.

User avatar
carrot
Regular
Posts: 28
Joined: Fri Jul 28, 2017 7:43 am
Contact:

Re: 2 Functions Interact With Each Other Question?

#2 Post by carrot »

In DAMAGE_DEBUFF_SKILL_PLAYER, just set:

Code: Select all

enemy.DEBUFFED_DAMAGE_HOLDER = 20 * enemy.PLAYER_DAMAGE / 100
instead of having it be a variable local to that method. And then when you're in COOLDOWNS_CHECK you can do:

Code: Select all

self.PLAYER_DAMAGE += self.DEBUFFED_DAMAGE_HOLDER

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: 2 Functions Interact With Each Other Question?

#3 Post by Nero »

Was thinking is there a way to work around with local variable just curious. But sure it works this way so my problem is fixed thanks.

User avatar
carrot
Regular
Posts: 28
Joined: Fri Jul 28, 2017 7:43 am
Contact:

Re: [SOLVED] 2 Functions Interact With Each Other Question?

#4 Post by carrot »

There's no way to do it with a local variable, by definition. If it's local to the method, it's discarded once the method returns.

There are a whole bunch of ways to pass data around between methods, but local variables don't persist outside of their scope, so unfortunately that's not something that would ever work.

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: [SOLVED] 2 Functions Interact With Each Other Question?

#5 Post by Nero »

it is good to know thanks for the information :). In ren'py you can defined local variable and use it for the whole game so I though maybe that's the case with python code too.

Post Reply

Who is online

Users browsing this forum: Google [Bot]