Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411656 Posts in 69395 Topics- by 58451 Members - Latest Member: Monkey Nuts

May 15, 2024, 04:21:09 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Why did I ever use game maker? Oh... Why?
Pages: [1] 2
Print
Author Topic: Why did I ever use game maker? Oh... Why?  (Read 6870 times)
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« on: April 05, 2010, 12:09:32 AM »

I've spent an entire day writing the following code, crushing bugs everywhere, and creating new ones as I've gone. All I want is a pretty inventory menu!

Code:
//Inventory_Menu(inv)

var sustain, tab, scroll, tabmax, tempsurf, pt, tempback, backcol, inv, alpha;
sustain = true;
tab = 0;
tabmax = 3;
scroll = 0;
pt = 3;
inv = argument[0];

alpha = 0;

invarray[0] = "Weapons";
invarray[1] = "Useable";
invarray[2] = "Loot";
invarray[3] = "Mail";

tempback = background_create_from_screen(0, 0, view_wview[0], view_hview[0], 0, 0, 1);
tempsurf = surface_create(view_wview[0], view_hview[0]);

backcol = make_color_rgb(214, 210, 150);

io_clear();

set_automatic_draw(false);
while (sustain) {
    io_handle();
    if (keyboard_check_pressed(key_inv)) sustain = false;
    if (keyboard_check_pressed(key_left)) {
        tab -= 1;
        scroll = 0;
        alpha = 0;
        if (tab < 0) tab = tabmax;
        io_clear();
    }
    if (keyboard_check_pressed(key_right)) {
        tab += 1;
        scroll = 0;
        alpha = 0;
        if (tab > tabmax) tab = 0;
        io_clear();
    }
    if (keyboard_check_pressed(key_up)) {
        scroll -= 1;
        if (scroll < 0) scroll = 0;
        io_clear();
    }
    if (keyboard_check_pressed(key_down)) {
        scroll += 1;
        if (scroll == ds_grid_width(inv)) scroll = ds_grid_width(inv)-1;
        io_clear();
    }
    //Draw functions
        //screen_redraw();
        surface_set_target(tempsurf);
        draw_background(tempback, 0, 0);
        draw_set_color(backcol);
        draw_set_alpha(0.55);
        draw_rectangle(0, 0, view_wview[0], view_hview[0], 0);
        draw_set_alpha(1);
        draw_set_color(c_black);
        var txt; txt = "";
        for(i = 0; i != 4; i += 1) {
            txt += invarray[i];
            txt += "    ";
        }
        var ptto;
        draw_set_font(fontGameMnLg);
        switch (tab) {
            case 0: ptto = 3; break;
            case 1: ptto = 3 - string_width(invarray[0]+"    "); break;
            case 2: ptto = 3 - string_width(invarray[0]+"    "+invarray[1]+"    "); break;
            case 3: ptto = 3 - string_width(invarray[0]+"    "+invarray[1]+"    "+invarray[2]+"    "); break;
        }
        if (pt != ptto) {
            pt += (ptto - pt)/((fps+1)*2);
        }
        draw_text(pt, 3, txt);
        alpha += 0.25/((fps+1));
        var stock;
        stock = 0;
        for(i = scroll+1; i != 30; i += 1) {
            var name, amt, ico, maxi, type;
            name = ds_grid_get(inv, i, 0);
            if (name != "" && stock < 5) {
                type = Items_Lookup(name, 3);
                //if (type == invarray[tab]) {
                    amt = string(ds_grid_get(inv, i, 1));
                    ico = Items_Lookup(name, 5);
                    maxi = Items_Lookup(name, 2);
                   
                    draw_set_alpha(alpha-stock);
                    draw_sprite_ext(spriteItemList, real(ico), 4, 50+(32*stock), 1, 1, 0, c_white, alpha-stock);

                    draw_set_font(fontGameMnMd);
                    draw_text(38, 50+(32*stock), name);
                   
                    var h;
                    h = string_height(name);
                   
                    draw_set_font(fontGameMnSm);
                    draw_text(38, 50+h+(32*stock), amt + " of " + maxi + " " + string(i) + " " + string(stock));
                    draw_set_alpha(1);
                   
                    stock += 1;
                //}
            }
        }
        surface_reset_target();
        draw_surface(tempsurf, 0, 0);
        screen_refresh();
}
set_automatic_draw(true);
surface_free(tempsurf);
background_delete(tempback);

I don't get what's going wrong.
I add 10 Mushroom Caps, and there's 1 Wolf Pellet in the experimental chest you can open. I end up with:


I don't expect much help since the entire thing pretty much revolves around a system I created to store items. But egh. I don't think this problem involves that system.

At the very least, consider this a hate thread(or at least srs frustration at the moment of writing) to game maker. As nice as it is, but when you need to do dirty technical things with data... Yeah. Considering how bad you can get with data manipulation, this isn't even very technical!
Logged

Skofo
Level 10
*****



View Profile
« Reply #1 on: April 05, 2010, 12:15:28 AM »

Mind filling us in on what the inventory is supposed to look like?

There are many reasons to hate Game Maker, but I'm pretty sure that Game Maker is not the reason your code is not working...
Logged

If you wish to make a video game from scratch, you must first invent the universe.
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #2 on: April 05, 2010, 12:18:36 AM »

I'm almost sure it's me. But it's the fact Game Maker allows me to cut corners in inefficient ways that I've made most of these problems so far.

It should be showing the mushroom caps, then the wolf pellet right below it. Rather than each item x5.

I know my inventory system is working fine-- it's the way I'm drawing it that is the problem.(I have a script which draws direct inventory data, and it showed how it should have.)
Logged

Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #3 on: April 05, 2010, 02:02:01 AM »

This is a pretty lame hate thread. It needs more foaming at the mouth, tantrums and barely coherent raves. Please have another go at it. Hand Any Key
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
muku
Level 10
*****


View Profile
« Reply #4 on: April 05, 2010, 02:20:23 AM »

Welcome to the world of debugging. This will happen to you no matter the choice of language as soon as you start writing nontrivial code.

I guess Game Maker doesn't come with a built-in debugger, huh? Barring that, does it at least offer a way to write text output to some console? If so, start sprinkling little diagnostic messages throughout your code, especially in your loop bodies, to figure out what's going wrong.

Besides, you should definitely comment your code so that you still understand it when you return to it in a few weeks' time. Also consider using more descriptive variable names.
Logged
nikki
Level 10
*****


View Profile
« Reply #5 on: April 05, 2010, 02:32:12 AM »

it's never too late to learn another language.

One with power, debugging tools, nice IDE options ,commandline possibilities and powerhouse coolness you could use....
But still , debugging is like 78% of the work (atleast in my case)


Why did you ever start using Gamemaker ?
Logged
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #6 on: April 05, 2010, 10:31:57 AM »

Welcome to the world of debugging. This will happen to you no matter the choice of language as soon as you start writing nontrivial code.

I guess Game Maker doesn't come with a built-in debugger, huh? Barring that, does it at least offer a way to write text output to some console? If so, start sprinkling little diagnostic messages throughout your code, especially in your loop bodies, to figure out what's going wrong.

Besides, you should definitely comment your code so that you still understand it when you return to it in a few weeks' time. Also consider using more descriptive variable names.

Quite true.

It's built in debugger isn't very helpful-- You just get a dialog window which you can instruct to watch variables for you.

Diagnostic messages are usually the way I go, but in this case I can't figure out what the problem is.

As for the commenting.... Yeah, I should.  Concerned
Bad habit.
it's never too late to learn another language.

One with power, debugging tools, nice IDE options ,commandline possibilities and powerhouse coolness you could use....
But still , debugging is like 78% of the work (atleast in my case)


Why did you ever start using Gamemaker ?

Like C++? C#? Objective-C? AS3?
Yeah I'm familiar with all of those, but only particularly experienced with C++, but in regards to how experienced some are I'm not that experienced.

I chose Game Maker because I wanted to make the game fast, and didn't want to spend a load of time making a framework myself.(that would undoubtedly be buggier than this)  Tongue

This is a pretty lame hate thread. It needs more foaming at the mouth, tantrums and barely coherent raves. Please have another go at it. Hand Any Key
Cheesy

Since this is such a lame hate thread, and I can't seem to spot this bug, is it possible that anyone else has managed to?  Shrug
Logged

muku
Level 10
*****


View Profile
« Reply #7 on: April 05, 2010, 10:47:05 AM »

Since this is such a lame hate thread, and I can't seem to spot this bug, is it possible that anyone else has managed to?  Shrug

It's hard for me to read the code since I don't know GM, but I guess this is the main loop going through the inventory items?

Code:
        for(i = scroll+1; i != 30; i += 1) {

Do you ever check if you have reached the end of the inventory?
Logged
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #8 on: April 05, 2010, 10:56:02 AM »

Erm, I should have fixed that.

Yeah, it's going through the inventory-- The 30 is how many spaces are in the player's inventory. I was using the function ds_grid_width() to get it, but for some reason I suppose I changed it.
Logged

Skofo
Level 10
*****



View Profile
« Reply #9 on: April 05, 2010, 11:35:03 AM »

I can't seem to spot this bug, is it possible that anyone else has managed to?  Shrug

It'd be easier to debug if you posted a gm file with the inventory.
Logged

If you wish to make a video game from scratch, you must first invent the universe.
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #10 on: April 05, 2010, 01:01:28 PM »

Sorry, but no. That's too much of a hassle, and I don't feel comfortable giving out my entire game.(nothing personal, though!)

I figured it out.

It seems that when you declare variables in for loop functions in GM, the variable isn't destroyed after use. So when you do:
Code:
for(i = 0; i != 10; i += 1) {}

That i will be leftover afterwards. The problem was my script was taking the leftover i variables from my functions to get data from the Item library, causing an infinite loop.

So a lesson to everyone who uses GM, it's:
Code:
var i;
for(i = 0; i != 10; i += 1) {}
Logged

hexageek
Level 0
***



View Profile
« Reply #11 on: April 05, 2010, 02:14:25 PM »

so when you declare a variable in the for loop scope it doesn't get destroyed but when you declare a variable out of the for loop's scope it gets destroyed after the loop?
Facepalm
Logged
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #12 on: April 05, 2010, 02:22:03 PM »

With Game Maker, a 'var' declared variable will be destroyed after the script ends.

I know, though.  Facepalm
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #13 on: April 05, 2010, 02:39:36 PM »

yeah, there's no for loop scope or scopes in general. variables can be specific to scripts (using var), objects, or global.

i think gm's choice is a good one. it's not something that makes sense to programmers, but gm is not a programming tool, it's a way to make games quickly by simplifying things, and hiding the details. the beginning game developer doesn't usually need to know whether a variable is destroyed or not, or when it is, it'd just complicate the game for them. so i think it makes sense to do it the way gm does it. there's always trade-offs between ease of use and complexity/control.
Logged

nikki
Level 10
*****


View Profile
« Reply #14 on: April 05, 2010, 02:56:40 PM »

glad you found it
Logged
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #15 on: April 05, 2010, 03:01:15 PM »

Yeah, I agree with you Paul. Smiley

Honestly, I don't think most beginner users would try to do a menu the way I did.  Droop

After using different tools for almost 3 years(using compiled languages) I've just gotten used to and learned to appreciate the separatism you get with scopes.  Shrug
Logged

nikki
Level 10
*****


View Profile
« Reply #16 on: April 05, 2010, 03:14:50 PM »

Do you work with many 'smaller' scripts then? Or just be extra careful thinking of names of variables?

wait I'm curious now, i'll go to the site and have a look....
Logged
Falmil
Level 6
*


View Profile
« Reply #17 on: April 05, 2010, 04:04:16 PM »

I'm not seeing where the problem is in the code you provided. Nor do I see how this could create a problem unless you're using the variable 'i' outside the loop. Perhaps the problem is in good coding standards. If you're using 'i' for a loop counter, I don't think you should be using it for anything else or using it outside the loop. I can't see whether you are doing this in your code or not, though. Another issue, when checking the condition to exit a loop, you might want to exit if the counter reaches or goes over your max (i=0;i<MAX;i+=1) instead of exiting only if it equals your max (i=0;i!=MAX;i+=1).
Logged
BlueSweatshirt
Level 10
*****

the void


View Profile WWW
« Reply #18 on: April 05, 2010, 04:20:37 PM »

The problem was that functions I had created that I was using within the for loop were taking control of the i variable I was using, because the functions I had used an i variable inside of them for a for loop. I was previously under the assumption that variables defined within a for loop would be restricted to that scope in Game Maker, but was wrong.
Logged

Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #19 on: April 07, 2010, 02:16:25 PM »

i think gm's choice is a good one. it's not something that makes sense to programmers, but gm is not a programming tool, it's a way to make games quickly by simplifying things, and hiding the details. the beginning game developer doesn't usually need to know whether a variable is destroyed or not, or when it is, it'd just complicate the game for them. so i think it makes sense to do it the way gm does it. there's always trade-offs between ease of use and complexity/control.
Ehrm, Game Maker might be a rapid development tool that hides much of the programming for you, but that doesn't mean that the programming parts of it aren't programming, and that neophytes when they need to do code work won't actually be programming. In the most lenient possible interpretation the GM choice seems to break the principle of least surprise, and honestly, from all programming standards that language design wart is more a epic wtf than a gotcha. Oh well, it could be worse. It could be JavaScript. Well, hello there!
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic