RPG element: experience points/levelling up

0 favourites
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Greetings fellow C2 enthusiasts!

    Firstly just want to say hi and introduce myself: HI! Im Luke but call me 'moy' :) i bought C2 a short while ago for personal use, have gone through the jungle, space, and battlefield tutorials, and am thoroughly enjoying the software. I had no idea something like this even existed so i am amazed with it!

    Anyway, to the point at hand - From this Ive embarked on a quest to make my own game with Platform x RPG elements. I have most of the mechanics id like to implement planned out and tested but i would like to include some kind of XP/levelling up system and am having trouble trying to figure it out (im trying to get it all figured on paper before putting it into C2).

    I guess the bedrock of my question is: are there any tips you guys can give for adding such a feature to my game? or is there a tutorial ive missed that can help with this?

    If not dont worry but i just thought id ask :)

    Thanks in advance!

    moymoymoy

  • You just need some variables friend.

    On monster123 killed add 123 to xp.

    Experience >=123 set variable level = 2

    Level = 2 set variable strength+2

    Etc.

    Hope you get what I mean:)

  • Holy hell thats genius!

    I understood it would take variables, i just couldnt get my head around the action/event side of things.

    Thank you so much for your enlightenment :)

  • It depends on what type of leveling system you need, are you leveling your character as a whole or does each skill have an independent leveling system, are you gaining xp on enemy kill, enemy hit or level complete.

    But what it comes down to is the usage of variables and/or arrays/dictionaries. You need to write, mostly using arrays or dictionaries, the xp number for every way you want to be able to gain xp, 10xp for killing enemy A, 50xp for killing boss B, 30xp for solving puzzle C etc.

    After that you need to, using events, trigger the specific xp gain and add that number to the xp counter, which can also be recorded in an array, dictionary or a variable.

    After the xp counter hits a specific number, your character or skill gains a level.

    EDIT: I should type faster, or use easier examples.

  • I would track all those sorts of things in the instance variables of an array. So make an array (I suggest you also rename it to something like 'experience'), add the instance variable 'exp', 'level', etc. This is just cleaner than using global variables and the array isn't destroyed between layouts like other objects. Also, if you later decide to add levelling for another character, you can just clone your existing array instead of needing to add more variables.

    How to make a comprehensive levelling system is something quite complex, but for just a simple 'exp > 10,000: set level to 2' system, you should have no trouble.

    EDIT: Also if using the paid version, create a family for your experience arrays and add the instance variables to the family instead of the array itself. This just allows more options and quicker cleanup in the future.

  • Thanks a lot for your suggestions guys, much appreciated :)

    Im familiar with arrays in terms of C++ and OOP and with a quick scan of a couple of the array tutorials, i think i could pick it up. I like Beaverlicious's idea of variables as well however.

    I think what i'll do is give both ways a go and see what i feel comfortable doing :)

    If i knew how to upvote all your comments/suggestions i would do so xD

  • I would track all those sorts of things in the instance variables of an array. So make an array (I suggest you also rename it to something like 'experience'), add the instance variable 'exp', 'level', etc. This is just cleaner than using global variables and the array isn't destroyed between layouts like other objects. Also, if you later decide to add levelling for another character, you can just clone your existing array instead of needing to add more variables.

    I don't really understand why you would use an array, but then use instance variables on it when you could add them to the character instead. That would save some picking.

    Although imo a good way to do is (imo) to put the status-array (that contains everything about the character's progress) in the container of the levelable character. So every new levelable character will have his own status-array when he is created, that also gets destroyed when he dies and that is automatically selected, when you pick the character.

  • mindfaQ - The problem with that is when they die/you change layouts, the experience is lost. By making it an array, it will not be destroyed allowing you to track it throughout the whole game and without causing mess with global variables.

    To make it work with multiple characters, you simply create a variable in the array called 'id' and set it the the relevant unit's UID. It does involve 1 extra condition for picking, but is more flexible. Alternatively, you could just add a name variable to the array and reference that.

    To me containers are not good for this sort of thing as you can't lose one without the other. If you decide later you want effects that, say, remove a character from play for X seconds, they now lose all their experience. You can make fixes and work-arounds of course, but that just keeps adding to the mess and requires more thought for solutions as these problems arise, instead of always knowing exactly what to do. And obviously if you want to carry experience between layouts, containers simply don't work at all.

    To reduce the need for picking, you can also use functions. So character kills enemy: call function 'getExp' with parameters: character.uid, experience amount. Then in that function, you can do all your picking and experience assigning. 1 condition, 1 action, less room for error and more room for improvement.

  • You can also use a mathematical function for your experience and stats curve.

    Let's say your character just got to level x :

    nextLevel (xp required) = ceil(ax^y)

    a and y being anything between 0 and +oo you simply set by hand.

    You can then plot your xp curve online to instantly see what values it's giving as an output. We're using desmos with my teammate, which is a great free tool available online :

    Desmos - online calculator

  • I see, forgot about that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I ended up writing a tutorial about this if you're interested.

    All questions or comments are welcome, it's my first tutorial and I'd like to see if anyone finds it useful/has problems with it.[

  • scirra.com/images/articles/createarray_3.png

    that won't work. It will always trigger if you don't destroy the default array (meaning you can get more than 1 array with the same name). If you destroy the array it will never run, because it doesn't properly check whether there is no array with the name in the game yet.

    Instead use something like this:

    on created

    • localvar = 0
    • array: id = player.name: set localvar = array.pickedcount
    • if localvar = 0: create the array and set the name
  • mindfaQ - oops! Thanks! I fixed it (name = player name (no action) followed by else: create array etc.).

    Tested it with a few different players at once and it works fine.

  • Oh yeah now I know what was on the tip of my tongue when I was writing this ^^.

  • could you help me understand what is happening here? ceil(ax^y)

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