Having trouble whith inventory working

A

Animo Tree

Guest
Right now I am working on a project, were if you click on an object on screen it will appear in your inventory on the corner of the screen. Here's my code...

if mouse_check_button(mb_left) and position_meeting(mouse_x, mouse_y, self){
for (var b = 0; Invintory_Box != 0; b++){
Invintory_Box = self
x = 423 + b
y = 702
}
}

The problem is, is that when you click on an object the code doesn't seem to run, instead the objects just stay where they are. The mouse_check_button action seems to be working, it's just the mouse collision doesn't seem to work. Any thoughts on how to fix it?
 

Gamebot

Member
Inventory is spelled differently between your post and the code. Maybe a double check.
mouse_check_button should be mouse_check_button_pressed ???
I assume your objects have sprites without them position_meeting won't work.

To draw your sprites correctly you will need a 1d or 2d array. What you have should be something like:

Code:
for(i = 0; i < len; i++)
{
 spr = inventory[ i ];
 draw_sprite(spr, xx + (i * sprite_width),  y)
}
You can find the next empty slot with a simple for loop and the built in array length functions. This way you can draw the object ect.. in order. You can use a number system or script to draw specific sprites. Without more code or info a bit hard to help.

If you want the object to disappear after its clicked use instance_destroy(object) when object is the name of the object or id of the one the mouse is over.
 
Last edited:
Top