Jump to content


Sonic180

Member Since 04 Nov 2003
Offline Last Active Jun 10 2013 02:34 PM

Topics I've Started

Game Maker decides it doesn't like code?

08 January 2013 - 05:39 AM

Hey there. I have been using Game Maker for... Well, since 2003 or 2004. I've always noticed that sometimes Game Maker decides it just doesn't agree with some code and it will start throwing errors left and right as a result. What causes this and is there a fix? For example, I've recently been working on a RPG game. I started a new project just to work on the inventory (as I was unsure of how to create it, I wanted a clean project to work with). One feature I wanted was a description box that appeared when I moused over an item. I started with only three items and got everything working. And then I added a new item and it started saying that there was unknown variables that I had clearly declared. It took adding a ton of code to it just to get it to realize that the variable WAS valid! Finally, everything was fixed and working so I started switching it over to my RPG project. Now I am having multiple problems. For one, every item takes the same image, and two, the description box no longer shows, but every single bit of the code is exactly the same and it works in my inventory .gmk file. Honestly, I'm out of ideas on fixing these problems. If it's Game Maker messing up, I don't see a way that I can solve it. Does anybody else have this problem? By the way, I am currently using 8.0.

Unknown Variable that has been declared?

07 January 2013 - 04:03 AM

I'm having a problem with an inventory system that I have been working on. When I mouse over an item inside of the inventory, a description box should appear. This worked perfectly for the first three items that were there from the beginning, but now that I am adding more items then it says that a certain variable is unknown and it says this for every new item I create. Here's the code inside of the items.

Create:
image_speed = 0;
image_index = 305;
stack = 1;
name = "Tin Greaves";
type = 0;
stat = "def";
amount = 10;
description = string(name) + "#This item can be equipped for " + string(amount) + " " + string(stat) + ".";
part = "feet";

And when you click on an item, this script is executed:

inv = obj_Inventory
stack = argument0;
found = false;

if (stack > 1) {
    for (i = 1; i < inv.slots; i += 1) {
        if (inv.slotItem[i] = object_index) {
            found = true;
            if (inv.slotNumber[i] < stack) {
                inv.slotNumber[i] += 1;
                instance_destroy();
                exit;
            } else {
                found = false;
            }
        }
    }
}

if (stack = 1 || found = false) {
    for (i = 1; i < inv.slots; i += 1) {
        if (inv.slotItem[i] = 0) {
            inv.slotItem[i] = object_index;
            inv.slotImage[i] = image_index+1;
            inv.slotNumber[i] += 1;
            inv.slotPart[i] = "";
            instance_destroy();
            exit;
        }
    }
}

show_message("Your inventory is full!");

And here is some code that's inside of the inventory object.

Create:
slotImage[slots] = 0;
slotItem[slots] = 0;
slotNumber[slots] = 0;
slotEquip[slots] = 0;
slotPart[slots] = "";

for (i = 0; i < slots; i += 1) {
    slotImage[i] = 0;
    slotItem[i] = 0;
    slotNumber[i] = 0;
    slotEquip[i] = 0;
    slotPart[i] = 0;
}

Step:
sRow = ((mouse_x - startX) div sprite_width) + 1;
column = ((mouse_y - startY) div sprite_height);
slot = (column * row) + sRow;

Draw:
if (mouse_x >= startX && mouse_y >= startY && mouse_x <= startX + (sprite_width * row) && mouse_y <= startY + (sprite_height * (slots / row)) && slot > 0 && slot <= slots) {
    if (!slotItem[slot] = 0) {
        draw_set_color(c_white);
        draw_rectangle(mouse_x+10,mouse_y,mouse_x+12+2+(string_width(slotItem[slot].description)+2),mouse_y+2+(string_height(slotItem[slot].description)+2),0);
        draw_set_color(c_black);
        draw_rectangle(mouse_x+10,mouse_y,mouse_x+12+2+(string_width(slotItem[slot].description)+2),mouse_y+2+(string_height(slotItem[slot].description)+2),1);
        draw_text(mouse_x+12,mouse_y+2,"" + string(slotItem[slot].description));
    }
}

Here's the error message, as well.

Message:
ERROR in
action number 1
of Draw Event
for object obj_Inventory:

Error in code at line 26:
           draw_rectangle(mouse_x+10,mouse_y,mouse_x+12+2+(string_width(slotItem[slot].description)+2),mouse_y+2+(string_height(slotItem[slot].description)+2),0);
                                                                                       ^
at position 86: Unknown variable description

Like I said, this works for the three items that I had from the beginning, but it doesn't work for any new items. Any help would be greatly appreciated.

More Advanced Lighting

16 November 2012 - 01:26 AM

Hey there. I've been trying for a long time to make a more advanced lighting system than what I have. I'm hoping someone could point me in the right direction for two things I want to add. Right now, I can create a basic lighting system by drawing a black layer over the screen using a surface and then subtracting a piece of the layer with a blend mode. The code is this:

Create:
light = surface_create(room_width,room_height);

Step:
surface_set_target(light);
draw_clear_alpha(c_black,0.8);
darw_set_blend_mode(bm_subtract);
draw_sprite(spr_Light,0,mouse_x,mouse_y);
draw_set_blend_mode(bm_normal);
surface_reset_target();

Draw:
draw_surface(light,0,0);

Now I want to add two things (and I don't think it's going to be completely possible with a subtract blend mode). I want to add the ability to change the color of the lights and I also want to add shadows. I'm almost positive the latter will be pretty complicated and I might not even get a straight answer here. I'm not asking for someone to make a system for me, but I would definitely like some help with figuring out the best way to create what I want. I've looked at tutorials on dynamic lighting, but they're normally very advanced and I have a hard time dissecting the code, especially when it has a bunch of other stuff added in. Anyways, any help or suggestions would be greatly appreciated.

Thanks in advance.

EDIT:

I have figured out a way to add color to the lights. I don't know why I didn't think of this before. The step event code is now:

Step:
surface_set_target(light);
draw_clear_alpha(c_black,0.8);
draw_set_blend_mode(bm_subtract);
draw_sprite(spr_Light,0,mouse_x,mouse_y);
draw_set_blend_mode(bm_normal);
draw_sprite_ext(spr_Light,0,mouse_x,mouse_y,1,1,0,c_red,0.5);
surface_reset_target();

This may or may not be the most efficient way, but it's simple and it gets the job done. Now I just need shadows.

Need a lock

15 November 2012 - 06:55 PM

Hey there. I was hoping someone could make an image of a lock for me? I'm working on a lock picking system which would be featured in some game, eventually. I'm hoping for one that looks fairly realistic, not cartoony. Any help would be appreciated.

Charcoal Rubbing (Calculating amount rubbed)

25 October 2012 - 11:15 AM

Hey there. When playing Uncharted: Golden Abyss, I got an idea for a game. I want mine to also have charcoal rubbings and I have already achieved this through surfaces, but I'm at a loss on how to calculate how much of the image you have revealed, and allow the player to proceed if it's enough. Does anyone know of a good way to do this? If you need to see the code for the rest of it, here it is:

Create:
image = surface_create(room_width,room_height);
paper = surface_create(room_width,room_height);

surface_set_target(paper);
draw_background(back2,0,0);
surface_reset_target();

surface_set_target(image);
draw_background_ext(back1,0,0,1,1,0,c_white,0.9);
surface_reset_target();

surface_set_target(paper);
draw_background(back2,0,0);
surface_reset_target();

Draw:
draw_surface(paper,0,0);

Step:
if (mouse_check_button(mb_left)) {
    surface_copy_part(paper,mouse_x-10,mouse_y-10,image,mouse_x,mouse_y,20,20);
}

Also, if anyone knows a way to solve another issue I'm having, that'd be great. The issue is, when dragging the mouse through the paper, if I go to fast then it's like GM can't keep up with everything; there's spaces in between the area my mouse last was, and where it's at now. I've tried changing the room speed, and it helps, but it doesn't completely fix it. But those are the problems. If anyone could help, I'd really appreciate it.