global variable

  1. K

    GML About variables and global variables

    I wanna know about the difference between them, is that variables are attached to the object only, and you can't use it in another object and global variables are available across all objects? I don't know if I am right.
  2. conman06

    GMS 2 Global Variable not working??

    Ok, so I'm making a game in which you click the trees, then they give you wood. I need to make an object to show how much wood the player has. In the tree object, I have these scripts for the Global Variable "Wood": global.Wood = 0; //When Tree clicked, add +1 wood and disappear. if...
  3. Axl Trauts

    SOLVED IF expression ignored using global variable even if false

    Hi, I am having a weird issue: When checking if the shark object player object is away from the player (to charge if closer), the IF statement runs even if the statement is false. The original relevant part of the Step event code on the Shark object is this: var dista =...
  4. Andrew Simms

    Mac OSX How to change a variable everywhere it's used?

    So I know GM2 discourages the use of some of the older universal variables like "Lives" and "Score" due to preservation issues, so I'm trying to change every use of "Lives" in my code to a new global variable I made. This is probably a simple fix but I haven't found anything online that did the...
  5. Corey

    (Fixed)Global variable/Alarm/instance_create issue

    Edit: Disregard. I fixed my problem by adding a Step event with global.enemyCounter = currentEnemies; to check the counter every frame and switched my Alarm event code to check conditions before spawning an enemy. Hello all. I have tried countless times to fix my problem. I am somewhat...
  6. H

    GMS 2 (SOLVED)Issue with setting local variable to (global variable value - amount)

    Hello, I keep getting the following error: when trying to do the following code: new_total_coins = old_total_coins - global.costume_price if(draw_coin_amount > new_total_coins) { switch(draw_coin_amount) { case 0: draw_coin_amount= global.coins_totalcollected...
  7. N

    Discussion can we have function like variable_global_get_name()

    Can we have variable_global_get_name() *function that gets name of all exist global variable in the room as an array of string I am trying to make debugger and already work around another similar function like variable_instance_exit /get_name /get /set which goes pretty well but when work around...
  8. P

    Keyboard_Check_Pressed(ord())

    For some reason when I input this code, instead of just activating key_z when the z key is pressed, it activates at any button pressed. Any ideas why? global.key_z = keyboard_check_pressed(ord(“Z”));
  9. Guitarmike

    Single-instance objects referenced by global variables

    Hi, I'm new to GML but not to programming. I'd like a little advice on best practices. I have a couple of objects in my game for which there is only a single instance and which need to be accessible from many other places around the game. For example, the obj_player and the obj_clock...
  10. V

    Global variables not working

    Hello, I am trying to make a game where the player falls from the top of the screen, collecting letters along the way. I have a text set up in the corner where I'm trying to have a fraction display the amount of letters collected/left. I'm using the following code inside a spawner object's draw...
  11. W

    Reading global variable

    My save/load system was planned with a few functions extra to make the game interaction more interesting, one of this functions is to variate the main menu background when a global variable has reached a certain value. I coded all the fuctions in the creation code of the main menu room, but...
  12. B

    Collision counter

    Hi there! I want to make a collision counter. I set to the object's create event to: global.collision = 0; And the collision event to: global.collision += 1; It counts constantly when it's overlapping, but I need just one point / collision. I have no idea, how can I do it.
  13. L

    Legacy GM Upgrade System Help

    I'm working on adding an upgrade system to my game where after the level timer runs out, it brings the player to an upgrade menu where you can spend points. I'm having trouble with a player movement speed upgrade at the moment. The idea is that selecting the upgrade option runs a script that...
  14. M

    GMS 2 Which is faster?

    I have a persistent invisible object called obj_game that controls most everything about my game: Which button is pressed, whether or not we're in a cutscene, how far we've gone along in the story, and whether or not the game is paused. [for example, if the variable global.paused = 1, the game...
  15. M

    GML crazy way to tincker with variables??

    I didn't know what to put in the title for this so I apologize for the click bate ish title My question is can there be two separate objects both programed with the same global.variable but that variable changes it's name based off of some state or position in the room?
  16. M

    Legacy GM detecting objects in seperate rooms?

    I'm wanting to check and see if there is an object already at a (x,y) position. Is there a way to do this when in a different room? I can provide some of my code to help with the context if need be/if asked but I don't see the necessity in that. Would it be more effective to use a global...
  17. P

    Legacy GM [Solved] Avoiding Memory Leaks With Particle Systems

    The manual recommends destroying Particle Systems when not in use as to avoid a memory leak, I gather in case different objects keep making unique systems and they pile up in memory. I was just wondering, if I store the particle system, particle type and emitter in global variables that all...
  18. P

    Tutorials and Global Variables

    Hello. So let me start by saying I am slowly learning more and more. One of the things I have learned is the potential disaster that is Global Variables. I have been following a tutorial on RTS Turn based games. However this tutorial, while teaching me a lot, left me in a hole I can't dig...
  19. H

    Legacy GM check for player using an item

    How can I check if a player is using an item and when the item is used it makes a global signal that can be used in an if statement
  20. Nathan Laing

    Legacy GM Which is slower, accessing global vars || another object's vars?

    Assuming one had to repeatedly access/assign a variable that exists outside of the object doing the accessing/assigning, Which would be slower; accessing/assigning a global variable or accessing/assigning another object's variable?
Top