• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Problem With My inventory [SOLVED]

A

Ash Ketchum

Guest
Hello everyone.

The problem with my inventory is when my player is in motion and the view is following him, i am not able to put items in the inventory.

So like.. I have 20 inventory slots, all follow the view in a 'top down' world. When the inventory slots are not forced to follow the view due to the player object moving. The slots work fine, i can pick up items and drop/take out them just fine.
But when there in motion it struggles to place them in because of how i coded it.
I'm not good with code at all, so it's all just bodged to get to work with what i know.
Sorry if that's a bad explanation.
Here's my code:

Cursor_obj

step event:
Code:
a = instance_nearest(mouse_x-16,mouse_y-16,PickUpParent_obj)
b = instance_nearest(mouse_x-16,mouse_y-16,slotP)
if item = 0
{
holding = 0
}
end step:
Code:
if item <> 0
{
item.x = x
item.y = y
}
global left pressed:
Code:
if position_meeting(mouse_x,mouse_y,a) and !position_meeting(mouse_x,mouse_y,b)
{
item = a
a.sprite_index = a.spr
a.sprite_index = invisible
}

if position_meeting(mouse_x,mouse_y,a) and position_meeting(mouse_x,mouse_y,b)
{
holding+=1
item = a
a.sprite_index = a.spr
a.sprite_index = invisible
b.item = 0
}

if holding = 2
{
   if position_meeting(mouse_x,mouse_y,b)
   {
      if b.item = 0
      {
      
      b.item = item
      item = 0
      holding = 1
      b.item.mask_index = invBox
      b.item.sprite_index = b.item.spr
      }
      else
      { 
      if b.item <> 0
      {     
      c = b.item
      b.item = item
      item = c
      holding = 1
      if item = 0 {holding = 0}
      b.item.mask_index = invBox
      b.item.sprite_index = b.item.spr
      }
      }
 
   }
}
////drop
 if !position_meeting(mouse_x,mouse_y,b)
 {
 holding +=1
 }
if holding = 2
{
   if !position_meeting(mouse_x,mouse_y,b)
   {
   holding +=1
   item.sprite_index = item.floorspr
   item.mask_index = smallMask
   item = 0
   holding = 0
   }
}
slotP (parent for all inventory slots)

create event:
Code:
item = 0
end step
Code:
if item <> 0
{
item.x = x 
item.y = y 
}
I know i haven't done this in the best way, but i tried, and failed :(
so i ask for help.

Thanks
 

KurtBlissZ

Member
I'm guessing the view gets moved before it checks the inventory.

Idk though, I think I would try putting your global mouse pressed event in the begin step or the end step event,
 
A

Ash Ketchum

Guest
I'm guessing the view gets moved before it checks the inventory.

Idk though, I think I would try putting your global mouse pressed event in the begin step or the end step event,
Hey. Thanks for the reply.

Good idea but , tried in both 'end' and 'begin' exact same result. (struggles to place the item.)
 
A

Ash Ketchum

Guest
Does it not work after your player moves? Or does it go back to working once your player stops?
It goes back to working when he stops.
also it works ok when the camera is going south, but not north.

this is the code for the camera:
Code:
if x-(view_wview[0]/2) > 0
{
view_xview[0] = x-(view_wview[0]/2)
}
else view_xview[0] = 0;

if view_xview[0] > room_width-view_wview[0]
{
view_xview[0] = room_width-view_wview[0]
}
////
if y-(view_hview[0]/2) > 0
{
view_yview[0] = y-(view_hview[0]/2)
}
else view_yview[0] = 0;

if view_yview[0] > room_height-view_hview[0]+180
{
view_yview[0] = room_height-view_hview[0]+180
}
 
I know this may be tedious, but I would definitely suggest single stepping through your code.
Run the game in debug mode and set breakpoints.
I would set a breakpoint in the global pressed event.

Then start moving and trigger that breakpoint.
Then, with the game paused on that breakpoint, I would set the breakpoints in the step and end step event. I would single step through the global pressed, making sure everything worked correctly. Then continue and let the step breakpoint hit. Double check everything there. Then continue and let the end step breakpoint hit.

That's how I would go about treating this issue.
 
A

Ash Ketchum

Guest
I know this may be tedious, but I would definitely suggest single stepping through your code.
Run the game in debug mode and set breakpoints.
I would set a breakpoint in the global pressed event.

Then start moving and trigger that breakpoint.
Then, with the game paused on that breakpoint, I would set the breakpoints in the step and end step event. I would single step through the global pressed, making sure everything worked correctly. Then continue and let the step breakpoint hit. Double check everything there. Then continue and let the end step breakpoint hit.

That's how I would go about treating this issue.
Thanks for the reply.
I am unfamiliar with breakpoints. This is an old project i'm finishing off in GM 8 btw
 
Top