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.
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...
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 =...
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...
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...
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...
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...
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”));
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...
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...
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...
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.
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...
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...
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?
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...
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...
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...
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?