• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

I'm super confused about this and really need help!

FeliX Games

Member
I have an object oController with:

-> Create Event:

GML:
/// @description player stats
global.level = 1;
global.exp = 0;
global.exp_till_next_level = global.level * 10;
global.player_hp = global.level + 100;
global.player_dmg = global.level + 10;
-> Step Event:
GML:
/// @description control player stats

// level up player
if (global.exp >= global.exp_till_next_level)
{
    var exp_remaining = global.exp % global.exp_till_next_level;
    global.exp = exp_remaining;
    global.level += 1;
}
I also have an object oButton with:

-> Create Event:

GML:
/// @description
isEnemy = false;

enemy_hp = (global.level * 1.5) + 50;

// default button values
image_speed = 0;
image_index = 0;
action = noone;
text = "N/A";
-> Step Event:
GML:
/// @description

// if the button is considered an enemy and its below or at 0 hp, destory self.
if (self.isEnemy == true)
{
    if (self.enemy_hp <= 0)
    {
        global.exp += 5;
        instance_destroy(self);
    }
}
-> Left Released Event:
GML:
/// @description button actions
switch (action)
{
    case 0: // deal damage to the pressed button.
        self.enemy_hp -= global.player_dmg;
        break;
}
All oButton objects Creation Codes contain this:
GML:
text = "Enemy";
action = 0;
isEnemy = true;
NOTE: There is no Room Creation Code.

I created an object to display the values of global.level, global.exp, and global.exp_till_next_level to check and debug the values.
I noticed something extremely weird going on with the global.exp value. I have it set to 0, but when I run the program it displays its value as 206.
This is a huge problem because it's causing
global.level to increase infinitely which I obviously don't want.

Any help is appreciated and I hope this is just a bug, and that it can be fixed!

Thanks for reading!

- FeliX
 

Roldy

Member
Couple things:
  1. Stop posting entirely in bold text
  2. Slow down and take things one step at a time
  3. Be careful and pay attention to your variable names ;)
Start with just your oController object; remove the buttons and the 'object to display the values.' Keep it simple and use show_debug_message for now. EDIT: seriously consider avoiding the use of global variables in general.

Once you know your oController is setup and functioning properly, add something back, test it and verify everything works. Continue this way, making small additions and testing thoroughly after each change. If you make small changes and something doesn't work, you don't have to be too confused on what might be going wrong, it is most likely the change you just made.

In short:
  1. Use simple and quick debug methods like show_debug_message
  2. Make small atomic changes
  3. Press F5 and run the game to verify things work properly
    • If there are problems, fix them
    • Press F5 and run the game to verify it is fixed; repeat
  4. Repeat until you have completed your game
Feel free to ask questions along the way like you have. There are plenty of helpful people in this community.
 
Last edited:

FeliX Games

Member
I went through my own debugging process and found nothing, that's why I posted here. funny thing is, I actually randomly decided to rename my variables, and the exp value is working as intended now. I'm assuming just having it named exp originally was messing with the "exp(n)" function? Also, about the global variables, I'm guessing I shouldn't use them because they take more space? So I should just use oController.<variable name> ?

Sorry if this was a dumb post, I'm relatively new to GML and just got back into it after maybe a year of not using it.
 

Roldy

Member
I went through my own debugging process and found nothing, that's why I posted here. funny thing is, I actually randomly decided to rename my variables, and the exp value is working as intended now. I'm assuming just having it named exp originally was messing with the "exp(n)" function? Also, about the global variables, I'm guessing I shouldn't use them because they take more space? So I should just use oController.<variable name> ?

Sorry if this was a dumb post, I'm relatively new to GML and just got back into it after maybe a year of not using it.

It was not dumb. In my opinion it is a bug. GMS should throw a warning or an error when you try to assign values to a constant. Yes, exp is the name of a built in function and has the constant value of '206.' FYI: i submitted a bug report and linked to this thread.

However, you would have caught this problem much quicker if you had slowed down and tested at each step. Also, even though I agree there is a bug here (needs to throw a warning at least), your assumption that something was wrong with GMS instead of your code is a bad habit to best to break it quickly. Always assume you are the problem, you will solve things much quicker.

The reason I suggest considering to avoid the use of global is that it is just a bit messy and lazy. GML isn't a strong object oriented language but it is loosely designed around those concepts. Make objects that perform specific task and have specific roles and keep all their data internally. There are some reasons where 'global' is handy and even necessary, however in your case all those variables could have been better owned by your oController object or a oPlayer object etc...

In this specific case if you had not use 'global.exp' the 'exp' text would have been colored like a function (orange) instead of like a global variable (purple) and might have help indicate the problem for you.
 
Last edited:

FeliX Games

Member
Was not dumb. In my opinion it is a bug. GMS should throw a warning or an error when you try to assign values to a constant. Yes, exp is the name of a built in function and has the constant value of '206.' FYI: i submitted a bug report and linked to this thread.

However, you would have caught this problem much quicker if you had slowed down and tested at each step. Also, even though I agree there is a bug here (needs to throw a warning at least), your assumption that something was wrong with GMS instead of your code is a good habit to break quickly. Always assume you are the problem, you will solve things much quicker.

The reason I suggest considering to avoid the use of global is that it is just a bit messy and lazy. GML isn't a strong object oriented language but it is designed around those concepts. Make objects that perform specific task and have specific roles and keep all their data internally. There are some reason where 'global' is handy and even necessary, however in your case all those variables could have been better own by your oController object or a oPlayer object etc...
Alright well, thanks for helping me out :)
 
Top