Making GML Easier Pt.2 (Custom Functions)
4 posters
Page 1 of 1
Making GML Easier Pt.2 (Custom Functions)
GML KNOWLEDGE NEEDED
I'm sure that you've checked out my old topic on making GML easier.
It talked about creating your own variables. Such as shortening "keyboard_check_pressed(ord('A'))" to something as small as "A" and as useful as that was I will now be showing you how to make your own functions!
(If you haven't seen my other topic then I believe you should, it's simpler than this.)
Now, I don't want to over-complicate this so here is something for your relief.
AFTER YOU DO THIS, EXPORT ALL OF YOUR SCRIPTS!
That way all you have to do later is import them.
Let's get started!
Now, let's say I wish to make a function that sets the direction and speed. (I know there is one already.)
You would create a script.
(Please do this now.)
Now I want you to name your script something like "motion" without the quotes.
(I'll explain how this works later.)
Now, create an object (make sure it has a sprite) and make a create event.
There are two ways to execute scripts, "script_execute" or you can just type the name of the script and give it parenthesis.
i.e. motion();
That would also execute the script. NOW REMEMBER! Your script has arguments!
So, in order, you would write the arguments within the parenthesis.
motion(4,0)
That would make your objects move at a speed of 4 in direction 0.
TADA!
Using this method you can make as many functions as you wish.
Combine them or make them from variables!
Even pros will find this useful.
All it does is set the arguments accordingly. motion(argument0,argument1)
There are up to 16 arguments so you can make really nice functions this way.
Well, enjoy!
-John
(If you find something wrong with this tutorial please tell me so I may fix it.)
I'm sure that you've checked out my old topic on making GML easier.
It talked about creating your own variables. Such as shortening "keyboard_check_pressed(ord('A'))" to something as small as "A" and as useful as that was I will now be showing you how to make your own functions!
(If you haven't seen my other topic then I believe you should, it's simpler than this.)
Now, I don't want to over-complicate this so here is something for your relief.
AFTER YOU DO THIS, EXPORT ALL OF YOUR SCRIPTS!
That way all you have to do later is import them.
Let's get started!
Now, let's say I wish to make a function that sets the direction and speed. (I know there is one already.)
You would create a script.
- Code:
speed = argument0
direction = argument1
(Please do this now.)
Now I want you to name your script something like "motion" without the quotes.
(I'll explain how this works later.)
Now, create an object (make sure it has a sprite) and make a create event.
There are two ways to execute scripts, "script_execute" or you can just type the name of the script and give it parenthesis.
i.e. motion();
That would also execute the script. NOW REMEMBER! Your script has arguments!
So, in order, you would write the arguments within the parenthesis.
motion(4,0)
That would make your objects move at a speed of 4 in direction 0.
TADA!
Using this method you can make as many functions as you wish.
Combine them or make them from variables!
Even pros will find this useful.
All it does is set the arguments accordingly. motion(argument0,argument1)
There are up to 16 arguments so you can make really nice functions this way.
Well, enjoy!
-John
(If you find something wrong with this tutorial please tell me so I may fix it.)
John(GmMkr-Admin)- Admin
- Number of posts : 501
Warning :
Reputation :
Registration date : 2008-07-17
Re: Making GML Easier Pt.2 (Custom Functions)
This is indeed a useful technique, and it helps keep code organized. I wish more people did this, especially when I'm helping someone by looking through their gmk... <_<
Re: Making GML Easier Pt.2 (Custom Functions)
Well thank you.
John(GmMkr-Admin)- Admin
- Number of posts : 501
Warning :
Reputation :
Registration date : 2008-07-17
Re: Making GML Easier Pt.2 (Custom Functions)
What about
render_HalfQ_BG (Number) 1 or 0
render_HalfQ_sprite ()
Sprite_Skip_frame (Number,Number)
This will half the graphics of the sprite.
Some time you want to half the visuals of the graphics. If you got a low-end computer.
Sprite_Skip_frame will skip the frames per each sprite. Also good for low end Computer.
The frames go as 1,3,5,7
The second number how much ship. Like I enter 2 then it will go as 0,2,4,6 frame.
render_HalfQ_BG (Number) 1 or 0
render_HalfQ_sprite ()
Sprite_Skip_frame (Number,Number)
This will half the graphics of the sprite.
Some time you want to half the visuals of the graphics. If you got a low-end computer.
Sprite_Skip_frame will skip the frames per each sprite. Also good for low end Computer.
The frames go as 1,3,5,7
The second number how much ship. Like I enter 2 then it will go as 0,2,4,6 frame.
DT-170x- Junior Member
-
Number of posts : 109
Age : 34
Location : Be a physic to know that question
Warning :
Reputation :
Registration date : 2008-08-22
Re: Making GML Easier Pt.2 (Custom Functions)
What are you getting at?
John(GmMkr-Admin)- Admin
- Number of posts : 501
Warning :
Reputation :
Registration date : 2008-07-17
Re: Making GML Easier Pt.2 (Custom Functions)
Not necessarily. There's no reason a given input couldn't be converted to GML and stuck in an object's event where it would be compiled and run at normal GML speed.
Creating your own language gives you a lot more control over what you let users do. GML might be too general and give too much control to users for your purposes.
======================
high speed internet providers
cv template download
Creating your own language gives you a lot more control over what you let users do. GML might be too general and give too much control to users for your purposes.
======================
high speed internet providers
cv template download
panneers740- Newbie
- Number of posts : 3
Warning :
Reputation :
Registration date : 2009-11-05
Similar topics
» Making GML Easier.
» Making a DLL
» About to quit OS making
» Need help making a JScript Game?
» Making Puzzle Games (Tutorial)
» Making a DLL
» About to quit OS making
» Need help making a JScript Game?
» Making Puzzle Games (Tutorial)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|