Adding Speed System In Game

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: 209
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Adding Speed System In Game

#1 Post by Nero » Wed Sep 06, 2017 12:59 pm

So I am making simple speed system of each character. Speed will determinant if player1 will start first or second dependent on speed he/she has. So my idea of doing this was to make something like "if player1.SPEED is >= enemy_list SPEED" .

My question is how do I check for ALL enemy_list members at once that their SPEED is higher than player1 speed?

Code: Select all

class Player(renpy.store.object):
    def __init__(self, SPEED=0):
        self.SPEED = self.SPEED


    default player1 = Player = (SPEED=20)
    default enemy1 = Player = (SPEED=50)
    default enemy2 = Player = (SPEED=51)
    default enemy3 = Player = (SPEED=52)


    $ enemy_list = [enemy1, enemy2, enemy3]

    "Now I want to check if player1.SPEED is >= than speed of enemy_list SPEED all together how do I do that?"

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: Adding Speed System In Game

#2 Post by DannyGMaster » Wed Sep 06, 2017 4:07 pm

If I understand correctly, you want to check each of the enemies in enemy party's separate speed with the player's? Something like:

Code: Select all

init python:

    class Player(renpy.store.object):
        def __init__(self, SPEED=0):
            self.SPEED = SPEED #This should be equal to SPEED, not self.SPEED

    #A method for checking the higher speed
    def getHighestSpeed(character, enemy_list):
        highest = "Player" #This system assumes the player is faster

        #If an enemy inside enemy_list has higher speed, change highest's value to "Enemy"
        for enemy in enemy_list:
            if enemy.SPEED > character.SPEED:
                highest = "Enemy"
            else:
                continue

        return highest

default player1 = Player(SPEED=80)
default enemy1 = Player(SPEED=50)
default enemy2 = Player(SPEED=51)
default enemy3 = Player(SPEED=52)

label battle_test:

    $ e_list = [enemy1, enemy2, enemy3]

    $ who = getHighestSpeed(player1, e_list)

    "[who] is faster!"
What this getHigherSpeed function do, when it's called, it uses a 'for' loop to iterate throughout the contents of enemy list. If it finds that an enemy's speed is higher than the players, it sets the variable highest to "Enemy". If not, it leaves it as it is, with the value "Player". It then returns this value, so you can store it in a variable or use it in a function.

This was written on the fly so there should be more elegant ways of doing this, but I have to leave now, so do some testing and see if it can be adapted to what you want.
The silent voice within one's heart whispers the most profound wisdom.

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

Re: Adding Speed System In Game

#3 Post by Nero » Thu Sep 07, 2017 4:22 am

Yes that's what I needed thanks!

Post Reply

Who is online

Users browsing this forum: Dascadi