1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

[solved]basic leveling system help

Discussion in 'Programming' started by Daripa, May 13, 2017.

  1. Daripa

    Daripa Guest

    so I run this code and if my lvl increases my hp doesn't :/
    can someone explain the logic behind this

    ///global
    //lvl
    global.lvl =1;
    //player hitpoints
    global.hp =100*global.lvl*1.25;
    global.hpmax =100*global.lvl*1.25;

    //EXP
    global.ex =0;
    global.exmax =100*global.lvl*1.25;

    //player Damage
    global.dmg = 50*global.lvl

    // enemy.hitpoints
    global.enemyhp = 1.25*global.lvl
     
  2. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    Where is that code? is all that in the same event?
    If so, global.lvl is always set to 1.
     
  3. Daripa

    Daripa Guest

    Yes its in the same event.. thank you, i'll chuck it in another and see what happens
     
  4. Daripa

    Daripa Guest

    lol i found the problem.. everything was in a create event, i had to move global.lvl into a step event..
     
    Last edited by a moderator: May 13, 2017
    NicoDT likes this.
  5. Daripa

    Daripa Guest

    well that didnt work exactly now my hp scales with my lvl but it cnt decrease :/
     
  6. arirish

    arirish Member

    Joined:
    Mar 13, 2017
    Posts:
    265
    It can't decrease because it's constantly being set to hpmax here:
    Code:
    global.hp =100*global.lvl*1.25;
    
    You need to break your code up into what needs to be set at the start (Create event), what needs to be checked constantly (Step), and what needs to happen when you hit a level up (probably also Step, but with some additional checks)
     
    Daripa likes this.
  7. Daripa

    Daripa Guest

    ill have to rethink this and incorporate a 2nd variable so i can run it in a step event :/
     
  8. arirish

    arirish Member

    Joined:
    Mar 13, 2017
    Posts:
    265
    You can chuck all that back in the Create event, and then in the Step event put (I think...):
    Code:
    if global.ex=global.exmax
    {
    global.lvl++;
    global.hp=global.hpmax;
    
    global.exmax =100*global.lvl*1.25;
    global.hpmax =100*global.lvl*1.25;
    }
     
  9. Daripa

    Daripa Guest

    thank you that worked :)
    just had to add global.hpmax =100*global.lvl*1.25; before
    global.hp=global.hpmax;
    and global.ex=0
    aswell as everything else to do with lvl
     
    Last edited by a moderator: May 13, 2017

Share This Page