It is very good, but I would rather have the coding on individual objects instead of just two controls. It would make it easier to understand which code goes for which item.
I find this very simple to understand, thanks a lot!
As for individual items, that would use way more memory than it needs to and with this, having their info in item_info, it keeps it well organized.
How could I get it to pop up when I press the 'I' key in my game and go away when I press 'I' again. I'm sure it's easy but I've never tried something like this before and no one seems to be able to help me. Credit will be given.
Edited by The Idiot 11, 13 December 2011 - 05:31 PM.
the amounts were all set to slotamount[1] .. not to 2 and 3
you draw the inventory from slot 1, but dragging can have the variable 0 ^^ so if you start dragging from outside the inventory and drop on a slot, then it goes to the non drawn slot 0..
your mouse_isin script goes like so:
if (argument) return 1 else return 0
the argument will be true or false either way, so you could just return it instead
return (argument)
does save a bit of prosessing power
very easy example tho I'm not a fan of checking mouse position in the loop, and you also draw it in the loop, which makes the text go behind the other slots, remember the position instead and do the text drawing below the inventory, se my fix below..
and confusing that the item sprite is transparent.. was confused by how the items suddenly appeared in the empty room at first.
@The Idiot 11: press I event: visible = !visible;
that will stop the draw event from running, another way is to stop a part of the event, for example if the draw event draws the inventory and the equipment window, then you do not want to close both:
show = true; // create event
show = !show; // press I event
if show = true{ // draw event
// drawing code here
}
@creators124 && remixx: how to fill a slot on drop, and drop outside inventory
I can try answer both of yours questions step by step: note: this does not work with the wrong default test values, see fix at top of post
Spoiler
draw event: - remove line 42 .. and 25 to 29 - change line 24 into:
if mouse_isin(drawX,drawY,drawX+31,drawY+31) over=i; // remember the slot mouse is over
- add this line at the top:
over = 0;
- then as a replacement for what we removed, put this at the bottom:
// Inventory have been draw, now check the slot the mouse is over or any mouse actions
draw_text(0,0,over) // <- this just draw the slot number, delete if you don't want it
if over > 0 {
draw_text(mouse_x+12,mouse_y+12, item_info(slotItems[over],0)) //draw its name
if mouse_check_button_pressed(mb_right) show_message(item_info(slotItems[over],1)) //rt_clicked
if mouse_check_button_pressed(mb_left) dragging=over
}
if mouse_check_button_released(mb_left){
if slotamounts[dragging]>0{ // this is to awoid that you can grab or drop a empty slot
if slotItems[over]= slotItems[dragging] item_fill(dragging,over) else // same item in both, try to fill it up and put remainding back
if over>0 item_switch(dragging,over) // if not dropped outside slot, switch items
else item_drop(dragging) // dropped outside slots, then create item and drop it
}
dragging=0;
}
- it also need 2 new scripts, just remember to name them after copying the code: item_fill
slotamounts[argument1]+= slotamounts[argument0] // move the full amount to slot one
slotamounts[argument0] = max(0, slotamounts[argument1]-10) // put the leftovers back, put all items more then 10 back, if less then set it to 0
slotamounts[argument1] = min(10, slotamounts[argument1] ) // then limit the top so it is max 10 there
if slotamounts[argument0] = 0 slotItems[argument0]=0; // if there are 0 items left, then remove the item
item_drop
var ins;
ins = instance_create(mouse_x,mouse_y,objPickup) // create item and remember its id
ins.mid = slotItems[argument0]; // use id to give it the item
ins.image_index = slotItems[argument0]; // and set its sprite to the same number
slotItems[argument0] = 0; // clear the inventory slot
slotamounts[argument0] = 0;
hope it's still easy to understand .. and will remove it if OP requests or adds some change like this to his file
Because someone asked how, I'm writing how to add an item to the system, it is actually very easy to do
1) In the sprItems, add a new image to the end. the image number is your item's ID (Image 1 is item with ID 1, etc.) 2) Open the script item_info. copy and paste this segment of code just after the very last break:
case 3: //Our Item ID
switch argument1 { //request
case 0: return 'Made by Vlad' break //name
case 1: return 'This tutorial was made by Vlad' break //description
//any extra description... (case *: return 'Value' break //extra damage)
}
break
3) Now you can add your item to the inventory with item_add(3) or whatever your item ID is!