Can I terminate script so it doesn't repeat itself on "if"?

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
User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Can I terminate script so it doesn't repeat itself on "if"?

#1 Post by Hellboy » Tue Dec 25, 2012 9:25 pm

The thing is, I'm doing a first person battle.
I want the enemy to look more trashed as the battle goes on. So I'm doing something like this:

Code: Select all

  if their_stamina < 80:
        hide Enemy100
        show Enemy80
        with dissolve
        $ renpy.pause (2.0, hard=True)
        "You have damaged the enemy's defense."
This makes the enemy image to deteriorate when his HP goes bellow 80, (then again at 60 with a similar script, then 40 and 20).

The problem is, if I attack the enemy again and his HP is still above 60, the script repeats again.
What I need is the script to run only once and then implode, so it doesn't repeat itself until I get to < 60 :lol:

Can someone please help me with that? I know it must be very simple, but I'm kinda new with this. I've been doing mostly fine with everything else on my own, but this is killing me. :oops:

User avatar
Jod
Regular
Posts: 51
Joined: Sat Nov 24, 2012 10:16 am
Projects: F.I.N.
Organization: JodCorp
Location: The Netherlands
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#2 Post by Jod » Tue Dec 25, 2012 11:19 pm

Hey there,

What you're looking for is if / elif. If the first 'if' statement isn't true, then it goes on to the second, etcetera etcetera. Then you check it from the other way around, working your way up from the lowest to highest, getting you something like this:

Code: Select all

if their_stamina < 20 
        hide Enemy40
        show Enemy20
elif their_stamina < 40
        hide Enemy60
        show Enemy40
elif their_stamina < 60
        hide Enemy80
        show Enemy60
elif their_stamina < 80
        hide Enemy100
        show Enemy80

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#3 Post by saguaro » Tue Dec 25, 2012 11:22 pm

Above is correct, but might also want to look into ConditionSwitch for this.

http://www.renpy.org/wiki/renpy/doc/ref ... tionSwitch

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#4 Post by Hellboy » Wed Dec 26, 2012 12:01 am

Jod wrote:Hey there,

What you're looking for is if / elif. If the first 'if' statement isn't true, then it goes on to the second, etcetera etcetera. Then you check it from the other way around, working your way up from the lowest to highest, getting you something like this:
Thanks! Unfortunately, it didn't worked (or I did it wrong), its giving me the same result. :|
saguaro wrote:Above is correct, but might also want to look into ConditionSwitch for this.

http://www.renpy.org/wiki/renpy/doc/ref ... tionSwitch
Thanks! Looks complicated, but I'll do my best. :shock:

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#5 Post by Hellboy » Wed Dec 26, 2012 11:13 am

Nope, I couldn't make it work. :(
But thanks for the help! It looked so easy, but its definitely driving me nuts! :)

User avatar
Jod
Regular
Posts: 51
Joined: Sat Nov 24, 2012 10:16 am
Projects: F.I.N.
Organization: JodCorp
Location: The Netherlands
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#6 Post by Jod » Wed Dec 26, 2012 12:34 pm

Hellboy wrote: Thanks! Unfortunately, it didn't worked (or I did it wrong), its giving me the same result. :|
That's really odd. Can you describe how it's not working? The way I described it, the code will run through the if-statement, but should always pick the correct one.
saguaro wrote:Above is correct, but might also want to look into ConditionSwitch for this.

http://www.renpy.org/wiki/renpy/doc/ref ... tionSwitch
That's a much, much neater solution. I didn't know that existed!

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#7 Post by Hellboy » Wed Dec 26, 2012 12:50 pm

Jod wrote:
Hellboy wrote: Thanks! Unfortunately, it didn't worked (or I did it wrong), its giving me the same result. :|
That's really odd. Can you describe how it's not working? The way I described it, the code will run through the if-statement, but should always pick the correct one.
It’s doing the same. If the enemy’s stamina goes, lets say 75, it shows the image and the text as it should, but if I strike again and his stamina is lets say 65, it repeats the same action. I’d like it to show the image and text when it goes bellow 80 only once. :|
Jod wrote:
saguaro wrote:Above is correct, but might also want to look into ConditionSwitch for this.

http://www.renpy.org/wiki/renpy/doc/ref ... tionSwitch
That's a much, much neater solution. I didn't know that existed!
Would someone please explain me a little what should I do with the ConditionSwitch? I tried it for hours, but I can't understand how it works. :oops:
Image
FREE and easy 3D customization, posing, and animation software with pre-made people and environments:
DAZ Studio Pro 4.9

User avatar
Jod
Regular
Posts: 51
Joined: Sat Nov 24, 2012 10:16 am
Projects: F.I.N.
Organization: JodCorp
Location: The Netherlands
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#8 Post by Jod » Thu Dec 27, 2012 9:34 am

Hellboy wrote: That's really odd. Can you describe how it's not working? The way I described it, the code will run through the if-statement, but should always pick the correct one.
Oh, now I get it!

I guess you could add a boolean to check if the image has been shown yet. The below is something quick and dirty and could no doubt be optimized, but...

When Initiating combat:

Code: Select all

Enemy20Shown = False
Enemy40Shown = False
Enemy60Shown = False
Enemy80Shown = False

Code: Select all

if their_stamina < 20 and not Enemy20Shown
        hide Enemy40
        show Enemy20
        Enemy20Shown = True
elif their_stamina < 40 and not Enemy40Shown
        hide Enemy60
        show Enemy40
        Enemy40Shown = True
elif their_stamina < 60 and not Enemy60Shown
        hide Enemy80
        show Enemy60
        Enemy60Shown = True
elif their_stamina < 80 and not Enemy80Shown
        hide Enemy100
        show Enemy80
        Enemy80Shown = True
This should prevent the image from showing when it's showing twice but still in the same damage-range. Still neater to do this with ConditionSwitch, I think.

Don't forget to use the Initiate Combat block I described above at the beginning of every combat or else this will only work for one combat! ;)
Would someone please explain me a little what should I do with the ConditionSwitch? I tried it for hours, but I can't understand how it works.
It's not completely necessary, but it's just a neater way of doing the above. When I have some more time I'll try to explain it further, but right now I have to work on my own project for a bit :).

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#9 Post by Hellboy » Thu Dec 27, 2012 2:15 pm

Finally, after 4 whole days of struggling with this only, your code saved me!
I had to tweak it a little to make it work, but probably its was me doing something else wrong in the first place. This is the variation I did (I don't really know what I did :lol: ):

Code: Select all

Not working as expected after all, so I remove the code to avoid confussing other members.
I'm still intrigued by the ConditionSwitch method, sounds like something important I should know, so yeah, I'd appreciate if you can show me a Condition Switch example when you get some free time, but you already helped me a lot.
I suck at coding, but I suck a little less at illustration, if I can return the favor with some graphic, let me know.

Thanks!
Last edited by Hellboy on Thu Dec 27, 2012 4:39 pm, edited 1 time in total.
Image
FREE and easy 3D customization, posing, and animation software with pre-made people and environments:
DAZ Studio Pro 4.9

User avatar
Greeny
Miko-Class Veteran
Posts: 921
Joined: Sun Dec 20, 2009 10:15 am
Completed: The Loop, The Madness
Projects: In Orbit, TBA
Organization: Gliese Productions
Location: Cantankerous Castle
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#10 Post by Greeny » Thu Dec 27, 2012 2:48 pm

The above code works, but it's very messy, especially if you have to fit this in between your other combat scripts. Learning to work with ConditionSwitch has the major advantage that it works automatically while you run your combat scripts; you don't have to shove it in your combat script somewhere.

Example.

Code: Select all

$ EnemyImage = ConditionSwitch(
    "their_stamina < 20", "enemy20.png",
    "their_stamina < 80", "enemy80.png",
    "True", "enemy100.png"
    )
Remember, the first bit between brackets is the variables you want to check, so to speak. The second one is the image you want to use when that equation is True.
Then, just work backwards; starting with a pair of the least likely clause working your way to ["True", "image.png"] which is the image that will be show if nothing else applies.
In Orbit [WIP] | Gliese is now doing weekly erratic VN reviews! The latest: Halloween Otome!
Gliese Productions | Facebook | Twitter
Image

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#11 Post by Hellboy » Thu Dec 27, 2012 4:38 pm

Hmmm... seems my variation had issues after all. I ended with something very close to your script Jod, just added some : and $ here and there and some details to cover more posibilities (like going from the 80 to the 40 range at once). But this time it seems to be working as expected. I'll remove the code on the previous message to avoid confussing other users. Thanks again!
Greeny wrote:The above code works, but it's very messy, especially if you have to fit this in between your other combat scripts. Learning to work with ConditionSwitch has the major advantage that it works automatically while you run your combat scripts; you don't have to shove it in your combat script somewhere.

Example.

Code: Select all

$ EnemyImage = ConditionSwitch(
    "their_stamina < 20", "enemy20.png",
    "their_stamina < 80", "enemy80.png",
    "True", "enemy100.png"
    )
Remember, the first bit between brackets is the variables you want to check, so to speak. The second one is the image you want to use when that equation is True.
Then, just work backwards; starting with a pair of the least likely clause working your way to ["True", "image.png"] which is the image that will be show if nothing else applies.
Thank you! I will study this more. I couldn't make it function, but I just need to try more how it works. I'll keep this at hand. Thanks for the explanation!
Image
FREE and easy 3D customization, posing, and animation software with pre-made people and environments:
DAZ Studio Pro 4.9

User avatar
Jod
Regular
Posts: 51
Joined: Sat Nov 24, 2012 10:16 am
Projects: F.I.N.
Organization: JodCorp
Location: The Netherlands
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#12 Post by Jod » Sat Dec 29, 2012 11:02 pm

Hellboy wrote:Hmmm... seems my variation had issues after all. I ended with something very close to your script Jod, just added some : and $ here and there and some details to cover more posibilities (like going from the 80 to the 40 range at once). But this time it seems to be working as expected. I'll remove the code on the previous message to avoid confussing other users. Thanks again!
I'm really glad you got it to work! Figuring this stuff out can be frustrating at times, but with some perseverance it's usually quite possible to get it to work.
I'm still intrigued by the ConditionSwitch method, sounds like something important I should know, so yeah, I'd appreciate if you can show me a Condition Switch example when you get some free time, but you already helped me a lot.
I suck at coding, but I suck a little less at illustration, if I can return the favor with some graphic, let me know.
I've checked out the ConditionSwitch method some more and I think it's going to be very useful for my own project. When I start to use it I'll probably make a detailed example post on my tumblr/thread here. Maybe the examples will help.

The ConditionSwitch is indeed a much neater way of dealing with this kind of thing. Of course it's not absolutely necessary, but it will save work in the long run, as well as making maintainability easier.

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Can I terminate script so it doesn't repeat itself on "i

#13 Post by Hellboy » Mon Dec 31, 2012 2:22 am

Jod wrote:
I've checked out the ConditionSwitch method some more and I think it's going to be very useful for my own project. When I start to use it I'll probably make a detailed example post on my tumblr/thread here. Maybe the examples will help.

The ConditionSwitch is indeed a much neater way of dealing with this kind of thing. Of course it's not absolutely necessary, but it will save work in the long run, as well as making maintainability easier.
That would be great! Let me know if you do please. The code you gave is working as I wanted, but it'll be great to know more about it. :D
Image
FREE and easy 3D customization, posing, and animation software with pre-made people and environments:
DAZ Studio Pro 4.9

Post Reply

Who is online

Users browsing this forum: No registered users