• 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!

GML My variable can be user from other event?

  • Thread starter David Motta Miranda
  • Start date
D

David Motta Miranda

Guest
My Create event generates a new variable named 'vida'. However, when I call for the variable in the Draw event, GM stops running. Are local variables connected to events (calling them when suitable)? should I create a new global variables to fix the problem?

Create:
Code:
var poder = 8;
var resistencia = 5;
var velocidade = 6;

var ataque = poder;
var critico = round(poder / 4);
var armadura = round(resistencia /4);
var vida = 30;

var esquiva = round(velocidade / 2);
var rapidez = round(velocidade / 2);
Draw
Code:
draw_set_colour(c_black);

draw_text(0,100,vida); // here the problem
draw_sprite(sprite2,0,x,y);
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
You would have seen that coming had you read up on scope.
The Manual said:
A local variable is one that we create for a specific event only and then discard when the event has finished (the only exception to this is in the script resources, where a var declared variable is local to the script and then discarded).
If every instance of that object should have its own vida variable, then declare it as an instance variable. If there should only be one vida variable across the board, then declare it as a global variable.
 
Top