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: Functions n Headers via Palib...would I be doing it right?  (Read 1082 times)

0 Members and 1 Guest are viewing this topic.
Functions n Headers via Palib...would I be doing...
« on: January 07, 2009, 01:18:05 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
I just read over headers and functions and other stuff with Palib.  Now, I am probably ahead of myself, but would you use functions as in a way you use objects with GM?
I am trying to best bridge the gap.
My problem is I know how to make a function, I just do not get in what capacity they can be used.  That's my issue with going from RADs to programming.
I don't want to make one HUGE ass repeat for one program that has useless code.

Would I be making functions and or headers and what not?

Like I said, probably wondering about something I shouldn't yet, but I just want to know the best comparison to GM.

Example:
Use a function for enemy missles.
Have a function for the level.
~ have the enemy missle function called when there needs to be a missle created

I am probably wrong, but I want to know and understand functions better.
PS Yeah I never really said much about headers >.<
Logged
  • Super Fan Gamers!
Re: Functions n Headers via Palib...would I be d...
« Reply #1 on: January 07, 2009, 01:35:06 am »
  • *
  • Reputation: +8/-0
  • Online Online
  • Gender: Male
  • Posts: 6604
Seems more like a C++ concern. The way I look at it is as follows. An object in Game Maker is the same as a class in C++, and an instance in Game Maker in C++ is an object of that class. From how I look at it, all objects in Game Maker all have something in common - the x, y, depth, id, and so on are all representative of the same thing.

Thus, I think that representing that in C++ would be something like having a base, abstract class called Object; with virtual functions so that you could not create an object from it. The child classes would be objects with different properties, characters, weapons, solid objects only, etc.

Of course, I may be wrong. Classes can have methods though as you know, which are like functions for each class.

My gut tells me that you would have a method in an object and in that object's method coding, you could call a function that you've created.
Logged

Pyrazor

PUMP UP DA JAMS!
Re: Functions n Headers via Palib...would I be d...
« Reply #2 on: January 07, 2009, 02:03:46 am »
  • OH LARD IZ PORKCHOP, BUST OUT DA HAPPY SNACKS
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 191
Think of it this way,

In GM you have  an object, so let's say Link.  This contains functions like Step, Create, and Destroy.  Those then contain logic.

To translate that into OOP you have a Link class.  This would have an Update function (or something to that extent) you'd call every iteration of the game.  This would be the equivalent of the step function in GML.  You'd have an Initialize function matching Create and potentially a Destroy function matching Destroy (though this isn't usually necessary).

The thing to note is that GM is pretty rigid.  A lot of the stuff it has functions for you could do in a single method in OOP.  For example, you could have one method that handles all input. 

So for the missile thing you'd have two classes, a missile class and an enemy class.  In your game's initialization you could spawn an enemy.  In the game's main loop you'd keep calling the enemy's update.  In the enemy's update, you'd have the logic to decide when to create a missile. 

You'd then have to keep updating the missile until it's destroyed for whatever reason.

It probably sounds complicated but it's really not too bad, just look up some examples or tutorials to get the feel for it.  If you understand the code then that should make clear how to put it into practice.
Logged

I C'Z U
Re: Functions n Headers via Palib...would I be d...
« Reply #3 on: January 07, 2009, 02:08:19 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
Think of it this way,

In GM you have  an object, so let's say Link.  This contains functions like Step, Create, and Destroy.  Those then contain logic.

To translate that into OOP you have a Link class.  This would have an Update function (or something to that extent) you'd call every iteration of the game.  This would be the equivalent of the step function in GML.  You'd have an Initialize function matching Create and potentially a Destroy function matching Destroy (though this isn't usually necessary).

The thing to note is that GM is pretty rigid.  A lot of the stuff it has functions for you could do in a single method in OOP.  For example, you could have one method that handles all input. 

So for the missile thing you'd have two classes, a missile class and an enemy class.  In your game's initialization you could spawn an enemy.  In the game's main loop you'd keep calling the enemy's update.  In the enemy's update, you'd have the logic to decide when to create a missile. 

You'd then have to keep updating the missile until it's destroyed for whatever reason.

It probably sounds complicated but it's really not too bad, just look up some examples or tutorials to get the feel for it.  If you understand the code then that should make clear how to put it into practice.

<3  That's the best way(for me anyhow) someone has explained something I can comprehend.

EDIT: So, would a good way to make a enemy be using another C source file?
Have that source file contain the updates, etc. and call it?
« Last Edit: January 07, 2009, 02:14:40 am by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: Functions n Headers via Palib...would I be d...
« Reply #4 on: January 07, 2009, 02:31:22 am »
  • *
  • Reputation: +8/-0
  • Online Online
  • Gender: Male
  • Posts: 6604
With classes (but not template classes), you mainly put the "description" of a class into a header file; with header guards for good measure to avoid multiple definition. You put the "explanation" of the class into a source file. This is the code for all the methods. The point of the separation is that some classes will need to know what something in another class is to be able to interact with it.

But like I was getting at, the enemies are likely going to share a lot of similarities in terms of variables and whatnot. It is good to consider inheritance and derived classes. Especially if you want to do things that Game Maker does easily such as instance counts, instance at position, etc.
Logged

Pyrazor

PUMP UP DA JAMS!
Re: Functions n Headers via Palib...would I be d...
« Reply #5 on: January 07, 2009, 02:33:31 am »
  • OH LARD IZ PORKCHOP, BUST OUT DA HAPPY SNACKS
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 191
Making another file is usually the best way to go for it.  You could have multiple classes in a single file but that involves certain complications that you don't want to deal with.

Inheritance is something you should look into, it'll save a lot of time when you're writing code for enemies, weapons, and the like.
Logged

I C'Z U
Re: Functions n Headers via Palib...would I be d...
« Reply #6 on: January 07, 2009, 07:06:19 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Yea, look into inheritance.  You can write a base class for an npc for example, that will contain all the functions and variables that every npc in your game will have.  Then you can derive a class for a specific npc from that class that will have the members of the base class as well as any new members you add to it.  Like you asked, you would use multiple files, the header and the source.  The header has the declerations, so that the game knows what they are.  The source has the definitions, so the game knows what they do.  You can create objects of the class in your program that will execute those functions in the class and use the variables.  Each object you create has its own set of the members of that class, so you could look at it like objects in GM from the perspective.
Logged



i love big weenies and i cannot lie

hacker013

Zelda Fan Game Programmer
Re: Functions n Headers via Palib...would I be d...
« Reply #7 on: January 22, 2009, 06:54:12 pm »
  • Ura Zelda Project Rocks
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 50
maybe is it better that you switch down to libnds because palib is outdated
Logged
  • Ura Zelda Project
Pages: [1]   Go Up

 


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



Page created in 0.215 seconds with 54 queries.