• 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 Visual I don't know how to make a global variable like inventory with the D&D option

H

hecan

Guest
Title says all ^

I am using gamemaker 1.4

Moderator Edit: Double posts merged. Please use the Edit button to add more information.
 
Last edited by a moderator:

Shawn Basnett

Discount Dev
I imagine Drag'N'Drop won't be very useful for this sort of thing, being that you cannot create arrays with it. Unless someone has a way to create what you're looking for without them.
 

Perseus

Not Medusa
Forum Staff
Moderator
Use global. as a prefix to your variable names while declaring and accessing them. For instance, setting global.money to 0 in the Create event would make it a global variable, then you'll use global.money to get its value.
 
Use global. as a prefix to your variable names while declaring and accessing them. For instance, setting global.money to 0 in the Create event would make it a global variable, then you'll use global.money to get its value.
But the variable doesn't always need to contain the object's name as prefix?
Yeah and sorry if I bother asking in an old discussion.
 
Object's name? Could you rephrase your question, please?
Sure comrade, sorry.

In GameMaker (specifically the version named after the number 8 [Gamemaker 8]), once you create a variable, it requires you to call this same variable with the name of the object (an entity in which you can write or drag and drop actions in order to make it perform various scripted behaviours commonly know has "commands" or "codes") you gave the variable to.

For instance:
I have the object named ass_fart and I wish to give it a variable named seriousam. According to the program (because otherwise it will only lead up to fatal errors) I need to name the entire variable I want to create with the name of the object itself.
So, I have to create an Object (remember, called ass_fart), create a Create Event, add there a Variable Code (drag n drop brick if you wish), and name the variable ass_fart.seriousam.

Now I have a variable called ass_fart.seriousam, which perfectly works. My interrogative was related to a previous phrase made by the gentleman named Perseus, which says:
Perseus said:
Use global. as a prefix to your variable names while declaring and accessing them.
Since my owned version of the program called Gamemaker 8 (made by JojoGames incorporated) requires you to have the NAME as prefix to the object's variable you just created, I asked how am I supposed to achieve the action of making my variable "global" considering that is threated like a prefix too.
For instance:
Do I have to write my variable as ass_fart.global.seriousam?
Or there is different way to do so?

Also, I remind you that I'm using Drag and Drop system to code my entertainment program, so I would really like to avoid using codes in order to keep the coding of it persistent to the subject matter.
 

Tyg

Member
I imagine Drag'N'Drop won't be very useful for this sort of thing, being that you cannot create arrays with it. Unless someone has a way to create what you're looking for without them.
Umm..not sure where you get your info, but Drag n Drop is just a coding style, there is nothing that can't be done.
It is just a VISUAL DEVELOPMENT TOOL
and its great for rapid prototyping
Saying you can't do something in drag and drop is a MYTH, it just generates the code for you, GML is GML
right click on any objects event and select LIVE PREVIEW and you will see the code it generated
and any code that is not DnD can be easily clipped and placed in an exec code DnD

when using the function dnd you just leave the ( ) off to call it

Yes arrays can be declared. with assign var dnd [0,1,2]
i use ds_list for my inventory but that is my preferance i could use arrays.
or even arrays within my ds_list
and to answer your question there is a set and get global var dnd that you can use without the global prefix
but i would rather use the assign var dnd global.var so that you don't get confused which vars are global for getting and setting
Screenshot.jpgScreenshot2.jpg
 
Last edited:

Nidoking

Member
it requires you to call this same variable with the name of the object
This wasn't the case in GM 8 as far as I ever knew, and it certainly isn't true now. The question is where you're putting these actions - they must be associated with an Event, which in turn is associated with an Object. In order for them to run in the game, there must be an Instance of that Object (an ass_fart, if you must) existing in the game. That instance has its own scope for variables it can contain. Using the variable name without dot notation refers to that instance's scope. So seriousam alone will refer to that specific ass_fart's seroiusam variable.

It is only when referring to variables in a different scope that you will need to use dot notation. One possible scope is the global scope, where variables can live for the duration of the game without being tied down to any instance.

made by JojoGames incorporated
Also please tell me this is a poor joke or auto-translate of YoyoGames and you're not using a third-party knockoff program and asking about it on the official site.
 
It is only when referring to variables in a different scope that you will need to use dot notation. One possible scope is the global scope, where variables can live for the duration of the game without being tied down to any instance.
Ooooohh...
Now I got it, thanks comrade.

Also please tell me this is a poor joke or auto-translate of YoyoGames and you're not using a third-party knockoff program and asking about it on the official site.
I just mispelled YoYoGames comrade, chill.
I like behaving like a dumbass, but I'm not a Jojo fan. Or a bootleg program user. Or both.
 
Top