Hello new user, we noticed you are not a member of our forum yet. Some topics are not visible to guest and you will be unable to receive access without logging in.
Hello new user, we noticed you are not a member of our forum yet. Some topics are not visible to guest and you will be unable to receive access without logging in.
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomePortalLatest imagesSearchRegisterLog in
Please post any projects, you are involved in, on our Project Forum
Welcome to DragonWing Community.
Forum Administrators: Deshar, Luciole2831.
Forum Moderators: Masterswordsonicman, Red, SethEckos, Reborn574.
Please join our Forum Game.

 

 GML PART 1

Go down 
4 posters
AuthorMessage
SethEckos
Moderator
Moderator
SethEckos


Posts : 90
Join date : 2010-11-24
Age : 31
Location : Babylon

GML PART 1 Empty
PostSubject: GML PART 1   GML PART 1 Icon_minitimeSat Jan 29, 2011 5:31 pm

Game Maker Language try not too feel intimidated this shit is soo easy it will ingrave itself in your brain in time.

Part 1 - Basic setup of GML

Starting with the very basics here. You'll notice that the basic setup is the same as D&D (Drag and Drop) if you just read through it like a normal sentence. Also, note that capital letters DO matter! The built-in commands will always be lower case.


if something
do this
By replacing "something" with something such as a variable, you can tell GM what to do but only if it meets a requirement. Lets start by worrying about "something" rather then the "do this" part for now.

if Timer=1
do this
That code will "do this" as long as the variable "Timer" equals 1. You can also use < (less then) or > (greater then) in the place of the = sign. Remember "timer" and "Timer" are different so be sure to use correct capitalization! Also remember you must create a variable before using it by at least setting it to 0 in creation of the object.

if Timer>1
do this

if Timer > 1
do this
Here I just want to point out that spaces between everything doesn't really matter. The above code is the EXACT same as the one below it. They read the same so it's just a matter of what is easier to read for you.

if Timer >= 1
do this
Another thing you can do is use two >, =, or < signs. GM understands >= as being "greater than or equal to". Anytime you use a = with another though, remember the equal sign comes second. Also, instead of using a variable, you can use a command as I'm about to show you. The "if" commands are listed in the codeing box at the bottom when you start to type. All of which are explained in the help file. (GM manual)

if distance_to_object(me) = 10
do this
This may look like a big jump from the above codes but lets take a look at it. If the distance to the object "me" is equal to 10, it will "do this". (thats 10 pixels by the way) For this command, you probably would want to use > or < instead. This command is often used in enemy AI to detect how far from the player the enemy is or distance from a certain object. There is a section of this tutorial where I explain a bunch of commands such as this one. Check the index.

if distance_to_object(me) > 50 && Timer > 1
do this
Ok, this code is a little harder to understand but still easy to use. "&&" means just that... it means "and". So this code means, if the object "me" is further then 50 pixels away from this object AND this object's variable "Timer" is greater than 1, it will run the "do this" part of the code. Remember it will NOT do anything unless it meets both requirements. You can add as many requirements as you want by just putting more and more &&'s in there...

if Timer > 1 && < 10
do this
Can you see anything wrong with this code? Yes it is WRONG and GM will point that out. When using &&, it's kinda like using "if" only it's mixing it with another. When using &&, you must repeat the command or variable as if it were separate. Doing the above code makes GM think "if what is less then 10???"

if Timer > 1 && Timer < 10
do this
This code is helpful because it will only do the code when the variable is within the range of 2 to 9. This is the correct version of the code I said was wrong above.

if Timer >= 1 && Timer <= 10
do this
This is basically the same as the one before it only you can see I added some = signs in there. Instead of checking if it's only greater then or less then, now it will also accept it if it's equal to it which makes it give you a range from 1 to 10. VERY important you remember that if one of the symbols are going to be an = sign, that it's second. <> also would work. Basically checking to make sure it is not the amount which brings us to our next part...

if not Timer = 1
do this
Now this code looks a little different but it is just like using <> only it looks better and may be a little easier to read. (if Timer <> 1) There is yet another way to use not...

if Timer ! = 1
do this
That code is the exact same as the last. placing a ! in there works EXACTLY like putting "not". Using this and && in there you can make your codes look pretty complicated. :) Also, note that functions (almost anything but variables) need the ! before it instead of after. An easy way to know when it's before or after is if it has an = sign or not. If it does, it comes before the = sign. If not it comes before the function itself.

if Timer = 1 || Timer = 2
do this
This is the last of the shortcuts I'm gonna tell you about. Putting || in your code is like placing a mirror in there. This code will activate if Timer is equal to 1 OR equal to 2. Yes, this is a replacement for putting in "or". The | lines are made by holding shift and pressing the button above your enter key. You can use "or" if you prefer to not use symbols.


Now lets look further into the same codes as before but mess with the "do this" part.

if x = 255
x = 100
This code would check to see if the object's x value is exactly equal to 255. If it is then it will change the x value to the value 100 ; jumping your object to a different spot in the room to the left in this case.

if Timer >= 10
move_towards_point(10,20,30)
That code will check if Timer is equal or over 10. If it is, it will move the object towards the point 10x20 at the speed of 30. It may look a bit complicated but remember as you type "move_towards_point" it will show up under the coding area showing you the first number is x, the second it needs is y, and the last is spd which stands for speed. How about we add more then one effect now?

if Timer ! = 2 {
move_towards_point(10,20,30)
Timer = 2 }
Ok, now it's starting to look like code huh. Just break it down and see what it says. If timer is NOT (notice the ! in there making it mean not) equal to 2, it will move towards the point AND change Timer equal to 2 making the code not do anything else. Using { and } in your code is just like using brackets in D&D. If you have more then one effect, you will need to add { after the "if" part and then add a } at the end if the entire effect list. If you are using &&, you still only need one set of brackets for one effect. If you don't feel safe with brakets, you can always use them even for one effect if you want, they just arn't needed.

if Timer = 1 && distance_to_object(me) < 10 && x >= 10{
x = 1
y = 2
}
Notice I used 3 ifs but I still only need 1 set of brackets. You'll never need more then one set unless you have a requirement inside of a requirement like this.

if Timer = 1 || Timer = 2{
x = 300
y=200
if Timer = 2{
Timer =3
}}
If Timer is equal to 1 or equal to 2, it will move the object to 300x200 and if Timer was 2, it changes Timer to 3. Remember this code would still activate if Timer is 1 but it just will remain 1 at the end of this code. Also notice kindof randomized my spacing for everything. It may be a bit more messy but everything will still read correctly.


Also, remember you don't always need to use an "if" in your code.
Timer += 1
If your code is in the step event of an object, putting this code will make it constantly raise the value of "Timer" by 1. Don't ask why but anytime you raise an amount with GML you'll need the equal sign in there. (Timer + 1 won't work)

Timer = 1
This IS different because it would change the value of "Timer" to the value of 1 meaning it will just keep changing it to 1 (if put under step). If your going to do something like that, (for lag reasons) you may want to use something like this...

if Timer ! = 1
Timer = 1
Now again, assuming this code is under the "step" event of an object, this code will ONLY change Timer to 1 if it isn't already 1. Using the last code will be changing Timer to 1 every step of the game. Doing that kind of thing too many times WILL cause lag eventually because it's constantly loading those even when not needed.

Also, another helpful thing to learn is how to effect an object with the code being in another object.

x = Me.x
If there is an object named "Me" in the room and you run this code from another object, it will change the x value of this object to the object "Me"'s x value. Still with me?

x = Me.x
y = Me.y
This code will make the object 'stick' to the object "Me" by keeping the x and y values the same. Keep in mind it will only update every time you run the code. If in step and you havent changed the game speed, it will "jump" to the object 30 times each second. It's common to see it trail behind you by a few pixels before updating again. I'd recommend drawing a sprite for this instead of using objects but anyways...

x += 1
This code is most likely the type of code used in most platformers or RPGs. If put into the "keyboard right" event of an object, it will rapidly move the object to the right. using a - (minus) sign instead of the plus sign will cause it to go backwards making it (in this case) go left.



You should now know some of the major parts of coding. Now all that is left is learning the built-in codes from D&D and maybe a few more even. I'd recommend checking the help file (Game Maker Manual) and click the index tab. Then start to type some stuff in or use the search tab if you have no idea of the code you need.


Last edited by SethEckos on Sat Jan 29, 2011 5:39 pm; edited 3 times in total
Back to top Go down
Naes-Igasu
Elder Dragon
Elder Dragon
Naes-Igasu


Posts : 847
Join date : 2010-12-19
Age : 27
Location : florida

GML PART 1 Empty
PostSubject: Re: GML PART 1   GML PART 1 Icon_minitimeSat Jan 29, 2011 5:34 pm

Coding seems impossible...
Back to top Go down
Deshar
Admin
Admin
Deshar


Posts : 1931
Join date : 2010-10-04
Age : 35
Location : England

Forum Game Information
Level: 6
Class: Swordsman
Guild:: Masters of Conflict

GML PART 1 Empty
PostSubject: Re: GML PART 1   GML PART 1 Icon_minitimeSat Jan 29, 2011 5:56 pm

SethEckos wrote:

Also, remember you don't always need to use an "if" in your code.
Timer += 1
If your code is in the step event of an object, putting this code will make it constantly raise the value of "Timer" by 1. Don't ask why but anytime you raise an amount with GML you'll need the equal sign in there. (Timer + 1 won't work)

It's because the program reads the value as Timer increase equals one.

Without it you would read it as Timer increase one, which makes sense to us, but the computer doesn't think of it as an increase of timer one, instead it would think to attach the value 1 to the Timer. To make Timer1...And that's not an increase.

For example:

global.attack=1

The global variable known as attack equals the value of 1.

global.attack+=1

The global variable known as attack increase equals the value of 1.

global.attack+1

The global variable known as attack+1...Error.

global.attack + 1

The global variable known as attack in addition to the variable known as 1...Error.
Back to top Go down
Luciole2831
Admin
Admin
Luciole2831


Posts : 1501
Join date : 2010-10-01
Age : 27
Location : Florida, United states of america

Forum Game Information
Level: 5
Class: Rogue
Guild:: None

GML PART 1 Empty
PostSubject: Re: GML PART 1   GML PART 1 Icon_minitimeSun Jan 30, 2011 2:58 pm

Naes-Igasu wrote:
Coding seems impossible...
Back to top Go down
https://freerun.forumotion.net
Deshar
Admin
Admin
Deshar


Posts : 1931
Join date : 2010-10-04
Age : 35
Location : England

Forum Game Information
Level: 6
Class: Swordsman
Guild:: Masters of Conflict

GML PART 1 Empty
PostSubject: Re: GML PART 1   GML PART 1 Icon_minitimeMon Jan 31, 2011 4:28 pm

Once you know what each term means it gets easier.
Back to top Go down
Sponsored content





GML PART 1 Empty
PostSubject: Re: GML PART 1   GML PART 1 Icon_minitime

Back to top Go down
 
GML PART 1
Back to top 
Page 1 of 1
 Similar topics
-
» goku vs frieza part 1

Permissions in this forum:You cannot reply to topics in this forum
 :: Multimedia and Member Projects :: Tutorials :: Game Maker-
Jump to: