• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

My game had no issues, next time I run it a random issue pops up

P

peanutbuuter

Guest
I was using a marketplace extension for a top down shooter, and i added a draw event to draw your score.
There was one line of code saying: 'Score: ' and one more saying 'string(global.score)'
It worked fine, and a few weeks later when i ran it it said

In Object oPlayer, in Event CreateEvent action number 1 at line 46 : "score" is a global built-in and cannot be used as an instance variable
In Object oEnemy, in Event CollisionEvent_11 action number 1 at line 6 : "score" is a global built-in and cannot be used as an instance variable
In Object oGame, in Event DrawEvent action number 1 at line 16 : "score" is a global built-in and cannot be used as an instance variable
Compile Failed - Please check the Compile window for any additional information

Collision Event 11 is when the bullet collides with the enemy
 
In one of the recent versions of GMS they started tightening up on stopping bad coding practices where it was previously possible to set up a global variable with the same name as a built-in variable (one that already exists with the GMS engine). As there is already a built-in variable called "score", you will need to do one of the following:
1. Change your global.score to use the inbuilt score variable (should be as simple as removing the "global." from everywhere you are using it).
OR
2. Change your global.score to be something else (like global.playerScore) so that it no longer clashes with the built-in variable.

I would personally go with option 2 as I prefer to have my own score-keeping variables and try to rely on the built-in variables as little as possible (except for things like x, y)
 

chmod777

Member
I'd rather say they encourage bad coding practices with the use of their global built-in variables (which are deprecated in GMS2).

Code:
global.score = 0; // you can no longer use this...
score = 0; // but this global built-in variable instead...
image_index = 0; // that looks the same as instance variables
 
P

peanutbuuter

Guest
Thanks for the help! I changed the score variable and it worked!
 
Top