Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: GM Tutorial: How to solve most problems encountered by newbies!  (Read 10290 times)

0 Members and 1 Guest are viewing this topic.
GM Tutorial: How to solve most problems encounte...
« on: December 07, 2006, 03:51:24 am »
  • Huzzowee!
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 571
Most problems can be solved in a very simple, but somehow not so obvious, step: RTFM. In short, RTFM stands for "Read the Freaking Manual". Vulgar, yes, but true. It's a little known fact, but GameMaker has its own built-in help file which covers pretty much every aspect of the program and defines pretty much every command in the GML language. Too often I see a question asked by someone trying to find a snippet of code or a function which is clearly defined this manual.

Rather than wasting both your time and others' by creating such a topic, the first thing you should do is push that little "F1" key or click the button that looks like blue circle with a question mark on the toolbar. Scan through or search the manual for what you need. Sometimes being vague helps.

If you cannot find what you are looking for in the manual, stop and think about what you're trying to do. Think logically about the problem. What is it you want to do? How could it work? Break it down as much as possible. For example, on of the most common request I've seen in the past is a rupee engine. If you take a couple of minutes, you'll realize exactly how obscenely simple such an engine is in any language. Let's break it down now:
What needs to happen? - Numbers need to appear on the screen that show how many rupees we have.
How do you show something on the screen? - You need to draw it.
  - What do you need to draw? - Numbers
    - What are numbers? - Text
      - What have we learned? We need to find a command that draws text on the screen. The text we need to draw consists of numbers.
Now we go into our manual and do a bit of a search. We need to find something to draw some text. So we make a vague search for "draw text". Since everything in the manual is described, odds are a function that draws text will have those words in its description. Looking at the results, we have different possible categories. "Drawing actions" looks promising! We can see there that it's descripting a drag and drop function that draws text on the screen. That could work, but we want to make a complicated engine so we'll want the code for it. Let's keep going. Look through the section until you find a GML function that draws text. It's there, and you ought to find it along with how to use it. Let's keep going:

We can draw numbers now! But how do we get the numbers we want? - We need to record how many rupees we have.
How do we record numbers? - Variables.
  - What kind of variable do we need? - It needs to work with the object drawing the number of rupees as well as the object collecting the ruppees. More than one object means a global variable.
    - Should we use "global.rupees"? - Why not ;)

Alright, so now we need to make two objects. One to get the rupees and one to show the numbers. The one that gets the rupees can be the character if you already have one. The one that draws the number should be one that handles other HUD things like that. Let's continue with the questions:
  - How is the object going to draw the numbers? - With the drawing function we found
    - Where do drawing functions go? - In the draw step.
There we go! Now we know where we have to put our code. So make a new piece of code and put up our draw function.

Assuming you found the same draw code as I did, it's draw_text(x,y,string). Let's ask some more questions.
  - What are those things in the parenthesis? - Parameters. They tell the function what to do.
  - What do they mean?
    - What is x? The horizontal position.
    - What is y? The vertical position.
    - What is "string"? The text we want to show
      - What do the parameters do? They set where and what to draw! Whodathunkit?
Shall we try to make it work now? We've found where to put the code and how to make it work. So do it. One thing you have to be sure is that the the variable exists so make sure that it's set in the collector object at the start.

Does a number show? Is it a zero? If so that means that it's working but you have no rupees.
 - How do you get rupees? - You collect them!
   - How do you collect rupees? - Link touches them.
     - What does "touching" mean in GM? - A collision between two objects.
So we need a collision between the collector and the rupees. It should be simple enough to do. Collisions are so easy that they're their own event.
 - What needs to happen on the collision? - We need to get rupees and the rupees need to disappear so you can't get them twice.
   - Disappear? - Destroy
     - Destroy? - Look in the manual ;)
   - What about adding rupees? - That needs to happen too?
     - What records the rupees? - The variable we set up before.
       - How do you add to a variable? - Simple: variable += amount to add

It's all pretty much laid out and a very basic rupee system should be in place. Try it out and see if it works. If not, we get to have more fun. You get to debug! Debugging is pretty much the same process, except a lot of the time you get an error to go with it. Pay attention to the errors. They will tell you exactly where it's running into the problem. It will give you the object, the event and the line number in the code. Then it'll tell you the problem. Remember that the place it gives isn't necessarily the place that causes the problem, but rather the place that it affects. First, go straight to that line. Using what the error told you, look for the problem. Sometimes there's just a typo or a missing bracket. Sometimes it's more complicated.

Whether you get an error or it's just not working right, you need to ask yourself certain queations, "what is the problem?", "Why is it happening?", "What other objects/scripts affect this?", "Is the problem somewhere else?", "What should happen?", "What isn't happening?", and go through a similar process of questioning and searching to find the answers.

If you looked through the manual and are still totally oblivious to why something doesn't work or how to do anything, leave it alone for a couple hours, or better yet sleep on it. Then, try it again. Sometimes leaving it and trying it again with a fresh mind actually does work wonders.

Finally, when all else fails, come here and ask for help. You should only go to others for the answer as a last resort. At first it might seem like there's just too much you don't know, which is discouraging. But you should let it get to you since it's normal. And true for that matter. At first you don't know much. However, all it takes is the manual as some actual thought. Slowly but surely the questions diminish until the only ones left are because something is so terribly complicated that you need a master to help. Doing is the best way to learn, learn makes you better, being better means making games is easier.
"They say 'Don't sweat the little things!', but in the end, the little things are all that matter..."
Re: GM Tutorial: How to solve most problems enco...
« Reply #1 on: December 07, 2006, 03:49:07 pm »
  • Master Of Disaster
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 2330
This might be very useful

.TakaM was here
  • Lumeuni
Re: GM Tutorial: How to solve most problems enco...
« Reply #2 on: March 25, 2008, 01:35:29 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 245
Wow.  :o I decided today that I'm going to make a serious effort to start learning Game Maker and GML. So I entered this board to look at some of the tutorials.

And wow, this one definitely stands out for how awesome it is. It's actually focused on TEACHING the reader how to do it and come up with their own solutions, rather than just giving them free source code without the proper emphasis on the fact that the code is ONLY for education purposes.

This tutorial is going to be incredibly useful for me.  XD
« Last Edit: March 25, 2008, 01:38:45 am by legendarylugi »
Pages: [1]   Go Up


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved

Page created in 0.038 seconds with 43 queries.