RPG Tutorial [1/unknown]

This forum is currently in read-only mode.
From the Asset Store
Carousel Animation, make carousel of you image gallery or anything
  • ::RPG Tutorial - Actors, and experience points

    In a rpg your character is going to level up and to keep track you need experience points. I don't have much knowledge of Construct but I have knowledge for programming/variable work.

    If you're using python you need to setup an array, if your using just the event code listen

    Python:

    actor = [];
    actor[0,0] = "Mr.Cool"
    actor[0,1] = 1 // Level
    actor[0,2] = 70; // HP
    actor[0,3] = 70 // HP Max
    actor[0,4] = 0 // SP
    actor[0,5] = 20 // SP Max
    actor[0,6] = 5; // Strength
    actor[0,7] = 9; // Power
    actor[0,8] = 5; // Defence
    actor[0,9] = 4; // Speed
    actor[0,10] = 0; // XP
    actor[0,11] = 0; // Slot number
    [/code:1atxcsia]
    [code:1atxcsia]
    // Level/exp stuff
    mrcool_exp = [];
    mrcool_exp[0] = 50;
    mrcool_exp[1] = 134;
    // just keep doing the same until you reach Level 99/100.
    
    level up code
    if actor[0,10] >= mrcool_exp
       actor[0,10] +=1;
       // this is where you can display a level up message, and increase the stats. 
    [/code:1atxcsia]
    
    Please note I come from a C++, GML, C# background, if my coding is somewhat wrong just correct me please.
    
    I'll update this tutorial frequently.
  • if actor[0,10] >= mrcool_exp
       actor[0,10] +=1;[/code:dhvx14i2]
    
    I believe you meant actor[0,1] +=1;
    
    Carry on.
  • Hehe, my bad.

    Anyway, was I right in executing an array variable? I'm really just trying to learn switch over to python.

  • Nice. I might use this for my game. Just a heads up, I know this is pseudo code, but I'm pretty sure it would go like this:

    1 # Level[/code:opv9c5ma]
    
    instead of:
    
    [code:opv9c5ma]1 // Level[/code:opv9c5ma]
    
    # = comment in Python.
  • Oh I see. I'm just used to "//" for comments.

    I think ruby also uses "#" for comments.

  • Anyway, was I right in executing an array variable? I'm really just trying to learn switch over to python.

    You could also create your own class.

    class Actor:
        """Definition of the player characters"""
        
        def __init__(self):
            self.name = ""
            self.level = 0
            self.hp = 0
            self.hpmax = 0
            self.sp = 0
            self.spmax = 0
            self.strength = 0
            self.power = 0
            self.defence = 0
            self.speed = 0
            self.xp = 0
            self.slot = 0
    
    [/code:28afbaku]
    You create an instance of the class by referencing it:
    [code:28afbaku]my_actor = Actor()[/code:28afbaku]
    
    If all player characters start with a certain value, you would of course replace the appropiate values. Also, __init__ is not really a constructor, but works nearly the same way, because this method is automatically called as soon as the class is created. If you'd want to create a new instance of the class with certain values, you'd do this:
    [code:28afbaku]class Actor:
        """Definition of the player characters"""
        
        def __init__(self, name="", level=0):
            self.name = name
            self.level = level[/code:28afbaku]
    Now you could create an instance either way:
    [code:28afbaku]my_actor = Actor()
    dewey = Actor("Dewey", 2)[/code:28afbaku]
    You can still use a list to manage them:
    [code:28afbaku]actors = []
    actors.append(Actor("Dewey", 2))
    actors.append(Actor())
    actors[1].name = "Wanda"[/code:28afbaku]
    And the levelup code could be realized as a method of the Actor class:
    [code:28afbaku]class Actor:
        """Definition of the player characters"""
        
        def __init__(self, name="", level=0):
            self.name = name
            self.level = level
            self.xp = 0
            
        def try_lvlup(self, exp):
            if self.xp >= exp:
                self.level += 1
    [/code:28afbaku]
    Again, referenced and stored in a list, you'd call:
    [code:28afbaku]actors[1].try_lvlup(mrcool_exp)[/code:28afbaku]
    
    But I guess it's just a matter of taste. I prefer the class-way for easier code maintaining (adressing actor[0].strength is more readable than actor[0, 5])
  • > Anyway, was I right in executing an array variable? I'm really just trying to learn switch over to python.

    >

    You could also create your own class.

    class Actor:
        """Definition of the player characters"""
        
        def __init__(self):
            self.name = ""
            self.level = 0
            self.hp = 0
            self.hpmax = 0
            self.sp = 0
            self.spmax = 0
            self.strength = 0
            self.power = 0
            self.defence = 0
            self.speed = 0
            self.xp = 0
            self.slot = 0
    
    [/code:3gmi2e16]
    You create an instance of the class by referencing it:
    [code:3gmi2e16]my_actor = Actor()[/code:3gmi2e16]
    
    If all player characters start with a certain value, you would of course replace the appropiate values. Also, __init__ is not really a constructor, but works nearly the same way, because this method is automatically called as soon as the class is created. If you'd want to create a new instance of the class with certain values, you'd do this:
    [code:3gmi2e16]class Actor:
        """Definition of the player characters"""
        
        def __init__(self, name="", level=0):
            self.name = name
            self.level = level[/code:3gmi2e16]
    Now you could create an instance either way:
    [code:3gmi2e16]my_actor = Actor()
    dewey = Actor("Dewey", 2)[/code:3gmi2e16]
    You can still use a list to manage them:
    [code:3gmi2e16]actors = []
    actors.append(Actor("Dewey", 2))
    actors.append(Actor())
    actors[1].name = "Wanda"[/code:3gmi2e16]
    And the levelup code could be realized as a method of the Actor class:
    [code:3gmi2e16]class Actor:
        """Definition of the player characters"""
        
        def __init__(self, name="", level=0):
            self.name = name
            self.level = level
            self.xp = 0
            
        def try_lvlup(self, exp):
            if self.xp >= exp:
                self.level += 1
    [/code:3gmi2e16]
    Again, referenced and stored in a list, you'd call:
    [code:3gmi2e16]actors[1].try_lvlup(mrcool_exp)[/code:3gmi2e16]
    
    But I guess it's just a matter of taste. I prefer the class-way for easier code maintaining (adressing actor[0].strength is more readable than actor[0, 5])
    

    That's great dude!

  • I forgot to mention an important thing:

    [] <-creates a one-dimensional list, not an array

    So, to get a list working as an array you would need to do this:

    actor = [] 
    actor.append("Dewey")
    actor.append(1)
    # etc for all values
    
    actors = []
    actors.append(actor)[/code:27nea85c]
    
    A clear multi-dimensional array would be done with:
    [code:27nea85c]actor = [[] for i in range(6)][/code:27nea85c]
    This will create a list "actor" with 6 entries indexed from 0 to 5, and every entry is a list with no entries so far.
    [code:27nea85c]actor[0].append("Dewey")
    If actor[0][0] == "Dewey":
        # let Malcolm know about it [/code:27nea85c]
    
    But there's also a module esp for arrays, I didn't work with it yet: [url]http://docs.python.org/release/2.6.6/library/array.html[/url]
  • So to do something like this without Python, or with out loading a script, couldn't you make an internal array with array access?

    + System: For "points" from 1 to 9

    + System: mrgreen.Value('exp') Equal to LoopIndex("points")

    -> mrgreen: Set 'current' to (1,2,3,4,5,6,7,8,9)@LoopIndex("points")

    Haven't checked if it can take a string....

  • take a look at the second post here.

    http://www.rpgrevolution.com/forums/ind ... ntry447958

    Though, many if not anything can be done without python. Though, I don't think Mode7 can yet though.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • i believe mode 7 could be achieved without python

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)