Classy Classy Inventory Code

Yay, a new and improved inventory system!  I’m very proud of myself, though I still need to implement accessors, a.k.a replace the ds_grid checks with ds[# x,y] calls as they look much cleaner.

function scr_additem(argument0,argument1,argument2){

     /*
     argument0 = item name
     argument1 = item sprite
     argument2 = item price
     */
     with obj_player{
     for(temp_height = 0;temp_height<bag_size;temp_height+=1){
          if obj_player.bag[# 0,temp_height] == “empty”{
               ds_grid_set(bag,0,temp_height,argument0)
               ds_grid_set(bag,1,temp_height,argument1)
               ds_grid_set(bag,2,temp_height,argument2)
               return true
               break
               }
          if temp_height+1 = bag_size{
               feed_text = “You can’t pick up the ” + argument0 + ” You invintory is full!”
               feed_text_count = 120
               return false
               }
          }
     }

Then i can use something like this in my pickup items collision with obj_player event!
if scr_additem(name,sprite,value) then instance_destroy()

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s