Whats the best way to learn GML?

Posted by JMchaos on June 8, 2006, 11:33 a.m.

All this time I havent ever tried to learn GML, much. It's hard to beleave I can do a lot of stuff without GML, but there are things I still cant do without GML. What's the best way to learn GML? Just looking at the help files?

Comments

elmernite 17 years, 11 months ago

Just using it. If you run into a problem. ask for help or check in the manual. The more you use it the better you get.

-Elmernite

marbs 17 years, 11 months ago

Start off by instead of using D&D, replace it with the code equivilent, e.g. replace the lightbulb thing with instance_create(x,y,obj_blah)

Thats how I started. Then go on and look at other peoples examples. You could use the manual, but the manual didn't (and still doesn't) help me overly loads.

DesertFox 17 years, 11 months ago

The best way, in fact, is to look at examples. They generally contain code, and you can always ask people for help.

Here's something that will be invaluable to you.

For loops.

For loops are useful, they let you repeat stuff under certain conditions.

They look like this:

var i;

for(i=0;i<x;i+=num){

code;

}

var means local variable - you dont need this, but it is best. local variables only exist in that script/code

for just initializes the loop

i=0 means that i starts as zero. Caution, though, if you have a variable named i, that variable is set to zero. You can use any variable with any name, and can change i to any number, even another variable.

i<x means the loop will run until i is no longer less than x. so if i starts as zero, and x is ten, it will will run ten times.

i+=1 means every time the loop runs, i adds that much to itself. you can use += -= */ or /= - those mean relative addition subtraction and stuff. i+=1 is just like saying i=i+1.

A sample code to create a bunch of bullets shooting out from you in a circle:

var i,b;

for(i=0;i<360;i+=45){

b=instance_create(x,y,obj_bullet);

b.direction=i;

}

b keeps track of the instance you created - you can access b's variables by saying b.direction and stuff.

also, you can use with(b){code} an that code will only run for instance b

Whew. Enjoy.

Magicman657 17 years, 11 months ago

Find yourself a mentor who has a few days to take you over the basics of programming (like if/ switch statements, loops, variables/constants, etc). After that, use the manual to learn the functions and variables. Over time they will become common knowledge and you can look up other ones.

Eternal 17 years, 11 months ago

I found that there are two things taht will help you:

First:

Learn the syntax. The page in Novice Q&A over at the GMC has a good D&D to GML site.

Remember { and } are like blocks.

Second:

Start typing in like 3 letters at a time, and functions show up at the bottom. Try to figure out what these do, sort of like looking words up in the dictionary to expand your vocabulary. Only funner.

DS 17 years, 11 months ago

Read the manual.

JMchaos 17 years, 10 months ago

Wow thanks, Ill try to learn but it will take time.