1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 The sprite and text are not the correct in the slot of inventory

Discussion in 'Programming' started by Tran Thi Huyen Trang, Jul 16, 2019.

  1. Tran Thi Huyen Trang

    Tran Thi Huyen Trang Member

    Joined:
    Oct 26, 2018
    Posts:
    12
    Hello everyone! I'm having trouble with my inventory system that I can't seem to fix. I've tried a lot of different things but nothing seems to work. so I'm just going to show you my code and hopefully you can help. If your not sure what some of the code means, ask me and I will explain it :) The problem is: the sprite of items and text of item amount are not the correct in the slot of inventory(backpack) that's mean: when i put the items in the slot 1 of Backpack, items will storage at slot 1, but the sprite and text of items amount will storage in the slot number 2 and slot number 8 (see in the image).
    Create:
    Code:
    ///initialize inventory
    slot_number = 20;
    inventory_width =4;
    ///new
    backpack_slot_number = 9;//6;
    backpack_slot_width = 9;//1
    backpack_slot_height = 1;
    backpack_slot = noone;
    backpack_slot_n = 0;
    //----For-Loop emptying all slots----
    for(var i = 0; i < slot_number; i++)
    {
        slot[i] = noone;
        slot_n[i] = 0;
        weapon_slot = noone;
        shield_slot = noone;
        backpack_slot[i] = noone;
        backpack_slot_n[i] = 0;
    }
    mouse_slot = noone;
    mouse_slot_n = 0;
    x_off = 200;
    backpackx_off = view_xview[0] + 8;
    backpacky_off = view_yview[0] + 468;
    DRAW:
    Code:
    //----Drawing backpack slots----
    
    //Checking backpack_slot_number and draw as many sprites as backpack_slot_number provides
    for(i = 0; i < backpack_slot_number; i++)
    {
      
        var xx = i mod backpack_slot_width;     
        var yy = i div backpack_slot_width;
      
      
    //Drawing backpack slots
    
    //draw_sprite(spr_backpack_slot, 0, 8 + xx * 64, 468 + yy );
    //draw_sprite(spr_backpack_slot, 0, 8 + xx * 64, 468 + yy * 64);
    draw_sprite_ext(spr_backpack_slot,0,8 + xx * 64,468 + yy ,2,2,0,c_white,1);
      
            if(backpack_slot[i] != noone)
            {
            
                //Drawing item and number etc.
                draw_sprite_ext(sprite[backpack_slot[i]],0,backpackx_off+xx *64+16,468+yy+16,2,2,0,c_white,1);
                //draw_sprite_ext(sprite[backpack_slot[i]], 0, 8 + xx * 32 + 16 + 3, 468 + yy * 32 + 16 + 2, 1, 1, 0, c_black, .4);
            
              
    
                draw_text(backpackx_off +xx *64, 468+yy *64, string(backpack_slot_n[i]));
               //draw_text( backpackx_off + (xx*64)/6 , 2 + 468 + yy , string(backpack_slot_n[i])); 
                draw_set_font(fnt_slot_number);
                draw_set_color(c_white);
        
                draw_set_font(-1);
                draw_set_color(-1);
            }
        
    }
    
    You can see the image I attached.
    Thanks for the help! :p
     

    Attached Files:

    • ppp.PNG
      ppp.PNG
      File size:
      26.1 KB
      Views:
      8
  2. Azenris

    Azenris Member

    Joined:
    Oct 30, 2016
    Posts:
    72
    If your backpack slots are the same size as your item sprites, and they use the same origin, you could calc the position once into a local, and use for both for drawing the backslot and item.
    Maybe this will reveal where the problem lies.

    How come you dont use backpacky_off, but you use the backpackx_off vesion, but then you only use backpackx_off in some places but not all.
    Maybe you need to delete the now unused lines ( save elsewhere ), and use some local vars to neaten it up.

    Also, you draw the text first, then you set the font, and then unset the font, the font is never used.
    you need
    set font
    draw font
    unsetfont
    Although you dont really need to unset fonts if you are always setting them before drawing text.

    Lot of magic numbers to make sense of. Maybe someone else will be of help :oops:
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice