Jump to content


Photo

Optimizing the game...


  • Please log in to reply
5 replies to this topic

#1 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2041 posts
  • Version:Mac

Posted 08 May 2012 - 01:12 PM

Do the key check commands slow the game any more than using the key check events? Would it be a bad idea to just put everything in the step event (using "else if" statements, of course)? Or should I really use the events as much as possible?
  • 0

#2 Manfrex

Manfrex

    GMC Member

  • GMC Member
  • 132 posts
  • Version:GM8

Posted 08 May 2012 - 01:22 PM

Do the key check commands slow the game any more than using the key check events? Would it be a bad idea to just put everything in the step event (using "else if" statements, of course)? Or should I really use the events as much as possible?


From what i have learned here on the forum, you should use the events as much as possible. And, theoretically, putting EVERYTHING in a single step event will slow down your game. This is because the game will not take a step until all of the code inside each step has been performed, but with events it just checks for an exception. Correct me if i'm wrong, someone! :smile:
  • 0

#3 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2404 posts
  • Version:GM:Studio

Posted 08 May 2012 - 03:03 PM

You're wrong.

Events are user-friendly ways of using code.
E.g. "Mouse Left Press Event" is the same as checking "if(mouse_check_button_pressed(mb_left)) { content of event }".
A computer always detects if you're pressing or moving something, it's just a matter of whether you want to detect it as well.

I suggest using programming as much as possible. I never use anything but Create, Draw, Alarms and Step events.

However, the killer of Game Maker is essentially the Draw event. Have as few Draw events as you possibly can - these are the most time consuming events in Game Maker, as they handle drawing.

A few handy tips;
1. Do not put any unnecessary code anywhere.
2. Never execute code that doesn't have to be executed at the given time.
3. Perform calculations as little as possible (if you're using a calculation many times, store it in a temporary variable in the start of the event - if it can change, else in a local variable in create event).
4. Clean your code.
5. Clean it again.
6. Double-check it.
7. Scavenge for more unnecessary double-calculations until you're absolutely sure there are none.

Edited by Jobo, 08 May 2012 - 03:05 PM.

  • 0

#4 Manfrex

Manfrex

    GMC Member

  • GMC Member
  • 132 posts
  • Version:GM8

Posted 08 May 2012 - 03:40 PM

You're wrong.

Events are user-friendly ways of using code.
E.g. "Mouse Left Press Event" is the same as checking "if(mouse_check_button_pressed(mb_left)) { content of event }".
A computer always detects if you're pressing or moving something, it's just a matter of whether you want to detect it as well.

I suggest using programming as much as possible. I never use anything but Create, Draw, Alarms and Step events.

However, the killer of Game Maker is essentially the Draw event. Have as few Draw events as you possibly can - these are the most time consuming events in Game Maker, as they handle drawing.

A few handy tips;
1. Do not put any unnecessary code anywhere.
2. Never execute code that doesn't have to be executed at the given time.
3. Perform calculations as little as possible (if you're using a calculation many times, store it in a temporary variable in the start of the event - if it can change, else in a local variable in create event).
4. Clean your code.
5. Clean it again.
6. Double-check it.
7. Scavenge for more unnecessary double-calculations until you're absolutely sure there are none.


I see... then i was mis-guided here on the forum before. :ermm:
Would you say that it is outright WRONG to use key-down events etc? If it's exactly the same as putting code in the step event, then i don't see the harm in using them, as i feel that it keeps my code more organized and "divided" rather then just being a 10000 lines long text with only comments to separate chunks of code apart. I assume, however, that the reason you suggest programming as much as possible is that you don't get lazy and always improve your programming skills that way? :smile:
  • 0

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16790 posts
  • Version:GM:Studio

Posted 08 May 2012 - 03:49 PM

The key events probably are actually ever so slightly (not enugh to count) quicker as they are compiled events and not coded ones. They are also timed differently and occur at different moments (much like the begin and end step) in a single game-tick, so you may also notice differences if your game relies on timing. Personally, I would encourage you to always use the events available to you as they help to organise your code into nice manageable "chunks" which makes editing and changing easier, but if you need something to run in the step event, or splitting it up is actually more confusing to you, then by all means have it all in the step event. Just remember the golden rule! Keep it simple for step and draw and do the complex stuff as little as possible and in other events!
  • 0

#6 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2404 posts
  • Version:GM:Studio

Posted 08 May 2012 - 04:35 PM

I assume, however, that the reason you suggest programming as much as possible is that you don't get lazy and always improve your programming skills that way?

Yes I personally suggest manually creating these events in Step event (or, for better precision when moving something, End Step event).
It's good programming practice if you're somewhat novice, you learn more of how Game Maker works (code-wise), and it ups your experience with programming in general - even when moving onto actual programming languages ("Hm.. Game Maker had a keyboard_ function, maybe this language has something similar.."). It really gives a nice way of thinking in general terms, when approaching something new.

I prefer programming these events myself for speed of use, instead of wobbling through multiple events to find what I'm looking for.
Click on object, click on Step, open code, and there's pretty much all the base coding.

Of course, with GM8.1 allowing you to rename "Execute code" action blocks, this allows you to organise it even better.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users