• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
nesseggman

Creating functions in GameMaker:Studio? And pseudo-enums?

3 posts in this topic

So, I am throwing together a prototype for my pet game, and I figured I'd try GameMaker:Studio to make it faster, but it seems like GML is very... limited and confusing.

Anyway, I only need to pass a couple hurdles and I should be able to create a functioning prototype that I can use to test the concepts of the game and get others' input and stuff.

So, the first thing I wanted to do was create some functions that will take care of various calculations and stuff. And I'm already stuck lol. Well, none of the documentation on GML seems to be very explicit on how things are done. I logged into the GameMaker Community and it won't let me make a new post and I searched there and here and couldn't figure out exactly how they worked.

It seems like you make a Script, but I don't know how to define the arguments for it. It seems like the arguments are defined by variables you call argument0, argument1, etc. throughout the Script you make. So I guess the arguments for your "function" are based on how many argumentX variables you write into the Script...

Then the example in the documentation looks like this:

//clamp_x(xmin, xmax)
//maintain x within the given bounds

if x > argument0 { x = argument0; }
else { if x < argument1 { x = argument1 } }

... It looks like the "notes" remind you of what arguments the function can take based on how many argumentX variables are in the code. But then the comments also state that it's supposed to keep x within the bounds... but I feel like argument0 should be what they're calling "xmin" and argument1 is what they're calling "xmax" ... but wouldn't they be the opposite, based on what the function apparently does...?

I'm assuming the documentation just uses a flawed example? That argument0 would be the ceiling and argument1 would be the floor of where you're trying to keep x inside.

So if I want to write a function, do I just put any number of argumentN variables in the Script, and then make comments at the top to remind me how many I had and what kind of parameters this function should be taking?

This seems needlessly complicated X_X; I wish the documentation actually explained how it works. It pretty much just says "Scripts can be used like functions." and then gives that example from above with no further explanation...

Also, since I can't really create an enum with GML or make states with one, let's say I wanted the user to be able to choose one of 20 pets or something, and then this choice will persist for the rest of the game, even between Rooms. I've created a global variable for this, but is it possible to use strings and check for the strings to use it kinda like an enum? Like, let's say they picked Pikachu (I'm not making a Pokémon game; it's just an example) then I could set global.petSpecies to "PIKACHU" and from there on out, on each room, I will need to display their pet. So I will create a function that will, through a tedious set of if statements, check all of the monster names, and then an if global.petSpecies == PIKACHU statement can tell the pet object that displays to change its sprite to the Pikachu set... does that seem like it will make sense? I honestly can't think of a better way to do it using GML :\

I'm using the free version of GameMaker:Studio so I can't create my own extensions using C++, nor can I use extensions others have made... I can only use the tools that GM:S comes with.

EDIT: And what all kinds of arguments can a Script function take? Like, could I pass a variable (rather than a value) or a pointer (are there even pointers in GML...?) to a variable? I'm assuming no, but who knows. The documentation does not explain how this works at all. Edited by nesseggman
0

Share this post


Link to post
Share on other sites

Thanks. I realized my Game Maker Community account was created a while ago but I never activated it through the email, so that's why I wasn't able to post new topics.

 

The biggest problem I have is the documentation is very vague sometimes, and sometimes leaves a lot unsaid, even if I search all over the place, trying to piece together how it works through all the help topics. The GMC is really hard to search because I'm typically bad at forum searches and usually when I find something with the same keywords, it's usually nothing related to what I'm wanting to know (in this case, I wasn't searching "script arguments" but rather stuff like "script as function" "creating function" etc. hoping to find some overview of all things scripts could do when working like a function)

 

The more I learn about it, the more GML seems to be useful, just... there's a lot of ambiguity and run-around in writing it sometimes.

 

I'm going to see if I can create some kind of... object that hides and stays 'instanced' throughout the game so I can make a sort of... class out of it, so I can make them for inventory, etc. It seems possible, but figuring out how to do it is going to be an adventure.

 

Well, thanks again!

0

Share this post


Link to post
Share on other sites

OK, I use GMStudio so I can help you.

For that clamping function, it looks wrong to me too.  It takes two arguments, which are argument0 and argument1, which correspond to the minimum and maximum that it will clamp the variable 'x' to.  But it seems you know a bit about reading code because yes, it is like the arguments are backwards.  But, as far as the arguments go, you are right, in that they are argument0 and argument1.  When GM "parses" that function, it looks for uses of those arguments, and that is how it determines how many the function needs, and so doesn't allow too many(or too few) when calling the function.  Also, a pointer I can give you is to look up the 'var' statement which creates a temporary variable that loses scope when the function is done.  If the script gets very complicated, it is more readable to set a few of those equal to the arguments, like this:


var xmin, xmax;
xmin = argument0;
xmax = argument1;


But, as of a very recent update to GMStudio, you can initialize the values on the same line as the declaration, where in previous versions you haven't been able to, though you always have been able to with "normal" variables.  Also, I haven't tested yet, but this behavior may actually be the only way to do it now, though I'm not sure since that update came out.

As far as the "enums" go, I know exactly what you mean because I need them too sometimes.  The way I handle that is with the constants.  Just like enums, each constant is equal to some specified integer, though you can actually make the value a string too if you wanted.  Then when writing your code, you would write the constant's name and the editor would replace all instances of it with whatever integer(or string) you made it.  This is also valid for switch statements, comparisons, etc... with no issues.  The constants you have specified also appear in the "intellisense" of the code editor too.  Also, the constants dialog have a save and load button so you could do so to a text file.  Once you see the formatting, it may become easier for you to input your constants via a text file if you are using lots of them.

About saving the state of the game, in general it is somewhat easy to use global variables.  But, if you have lots of things to save like that, then you can (and it is common to do so) use a few controller objects, that not only store values, but each game loop can do other things, like checking the remaining enemies, levelling characters, or anything else you need.  Also, you can check "persistant" in the dialog for the object, which makes that object not get destroyed when you change rooms, and so it stays around no matter what room you go into.

Well, have fun, and good luck.  If you need more help, you can PM me either here on the GMC, where I'm also known as kburkhart84.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0