[GameMaker Tutorial] Stacking RPG Inventory
Вставка
- Опубліковано 8 вер 2024
- Check out my popular GameMaker Book and GameMaker Courses: www.heartbeasts...
Video by Electric Donkey showing how to make this work with views: • [Extended GameMaker Tu...
Follow me on Twitch for GameMaker livestreams: / uheartbeast
Follow my twitter: / uheartbeast
Like my Facebook page: / heartbeast.studios
Follow me on Tumblr: / uheartbeast
Thank you all so much for your support!
That feeling of fear when he runs his room and doesn't get any error messages but you get one. He says, "Good, no error messages!" At that point, you know you are on your own trying to figure out where you went wrong. :)
+Puric Yato he can't hold our hands forever :c
the best errors are these, you make 3 videos ago... and you still search for the damn line
Every time you get an error you know you are on your way to learn something.
Nice to see this finally done, I've been waiting for ages to see you cover this!
There should be a part 2 about how to implement it into the game, how to change its position, how to change its size, how to change aesthetics, how to show/hide it, etc.
Hey Heartbeast, can you make an expanded tutorial on how to make one item take like 4 spaces, like in Deus Ex and Resident Evil 4?I think that would make items more realistic, a handgun would take like one space where as a shotgun would take 2 or 3.Thanks man, keep up the great vids!
Oh man you're working overtime dude, thanks for making another video today.
Hey Heartbeast, Love your Tutorials...
But, You've got YY is greater than width, instead of height.
And, the same for XX. 32:55
Amazing tutorial. I had a few errors here and there but was able to fix them by going through the comments are figuring it out myself. I was using different grid sizes and names, so I wasn't going by your exact code. Nonetheless, very great tutorial.
See link in description for video by Electric Donkey showing how to make this work with views: ua-cam.com/video/LMdXczEAn4c/v-deo.html
+HeartBeast
*FOR EVERYONE GETTING AN ERROR WHEN CHANGING THE DIMENSIONS OF THE INVENTORY*
at [ 33:10 ] he made a mistake, he linked the yy with width and xx with height (should be other way around)
Just switch those around
+HeartBeast *I made a drag and drop function for this inventory system check it out!:*
EVENT: Create:
// Drag and Drop
dnd = false;
dnd_item = item.none;
dnd_count = 0;
EVENT: Global left pressed:
///Drag and Drop
//Drag and drop (empty)
if dnd = false {
dnd_cords_x = x_to_gx(mouse_x);
dnd_cords_y = y_to_gy(mouse_y);
dnd_count = count[# dnd_cords_x, dnd_cords_y];
dnd_item = box[# dnd_cords_x, dnd_cords_y];
if !dnd_item = item.none {
dnd= true;
repeat(dnd_count) { inventory_remove_item(dnd_cords_x, dnd_cords_y); }
}
} else {
if dnd_item = item.none {
dnd = false;
repeat(dnd_count) { inventory_add_item(dnd_cords_x, dnd_cords_y, dnd_item); }
} else {
var gx = x_to_gx(mouse_x);
var gy = y_to_gy(mouse_y);
dnd_item2 = box[# gx, gy];
dnd_count2 = count[# gx, gy];
repeat(dnd_count2) { inventory_add_item(dnd_cords_x, dnd_cords_y, dnd_item2) }
repeat(dnd_count2) { inventory_remove_item(gx, gy, dnd_item2) }
repeat(dnd_count) { inventory_add_item(gx, gy, dnd_item) }
dnd = false;
}
}
What does not work?
+MrVesprFTW And, have you inserted everything in the right event?
when I click on a top half of a square nothing happens but when I click on the bottom half it adds the item and the stack circle is above the items
By changing the draw event to a draw GUI event the inventory worked well with my view system.
I know it's been quite a while since you've done this, but one thing that's challenging for me is trying to implement an 'equip' system. Where you have fixed slots (like on a character outline) and can drag/drop things from your inventory into the appropriate slot. The system could then check what item is in what slot and make changes to global variables (like the characters combat stats).Thoughts?
At 6:40 you can save an extra step. The grid values default at 0.
I wanna make an enchanting system where you can +1-+10 your armor/weapon. DO i have to make a seperate item for each + upgrade? What are some other faster ways to do it? Thanks
Good job with the videos as always. I would love to see a lets pixel on enemy slimes with animation
nice tutorial!
Your tutorials are just great...simple, clean and very well explained! Keep them coming ;)
(btw: if I want to add a item database, lets say, item: description, weight, use action, icon.. should it be done using a obj for each item? or would it be better to add a code segment in the "Inventory" create event handling the array of items?! do you have some ideias.. you could make some advice tutorials, not explaining everything... but giving pro and cons about several system implementations, like battle systems and menus and inventory)
Again, great work, and... is it possible to buy the physic copy of your book and ship it to Portugal (Europe)? :D
but can you maybe make a exstanded tutorial because i can't use my camera move's with my player and than the inventory disappears so can you help me please?
instead of a draw event put it into a draw gui event as a gui sticks to views
bonecrusher2002 tried it didn't work or i did it wrong.
+Abolin If you put it into the draw GUI (which I have tried) the issue is that when you click to remove/add an item, it thinks that you are out of the x and y range. This is because in the x_to_gx and y_to_gy scripts it is looking at the x and y co-ordinates of the inventory and then seeing how big the rest of the inventory is from there. As the inventory itself is drawing in the GUI, but the inventory's co-ordinates are still somewhere in the room. This tells the computer that the certain inventory is in the room (where you placed the object) however we see it as being in the GUI and on our screen. Hope you can understand that. I am currently working on putting this into the GUI and will reply when/if I finish :)
+Abolin I have changed a few bits of code to make it sorta do this. It can only be placed in the top left hand corner though atm. Here are the changes -
x_to_gx - Replace inventory.x with view_xview[0]
y_to_gy - Replace inventory.y with view_yview[0]
inventory draw - (Swap to draw GUI)
inventory draw GUI - Replace var tx = x+(xx*box_size); with var tx (xx*box_size);
((Do same with y, obviously changing the x to y))
Hope this helps :)
Electric Donkey thanks man
Hi Benjamin! I'm fairly new to programming and have a question about why you choose to have two ds_grids one for the item and one for the count? correct me if I'm wrong but couldn't one ds_grid hold both information? I read somewhere that data structures is pretty memory heavy on GM so it would make sense to use as few as possible, but I fear I'm missing something!
I really appreciate your videos, keep up the excellent work! :)
I learn all thinks of game maker .From thuis channel.Thx!
So how would you go about assigning things like item names and descriptions? This is ID-based, which is well and good, but the player would probably need more elaboration on what the item did other than a small image.
Is there a way to save this??
yes, with an advanced ds map you can, search for it
file_text_open_write and ds_grid_write?
Thank you for your wonderful lessons
Thanks a lot for this tutorial, Ben!
Hi. Thnx for this inventory. I got it working and also moving with my view.
But, how can I get a description of the items inside the inventory? So when I hoover with my mousepointer over a item, I get a little text what it is right next to the item count circle.
Hi, thank you for the amazing tutorial, quick question though, how can I set it up so if I have say a health potion in my inventory and I press a certain key on keyboard one item is removed?
How can I make the middle mouse button select the sword or whatever item I want to select?
so we have this handy script to find the grid the mouse is over but how do i find what item in in that slot?
Is it possible to add 'inventory slots' ? So the player could expand the inventory at some point during the game?
but how do I check the value of the item my mouse is hovering over?
So that when I remove it, I can actually check which item is being used?
That seems like really important information and I don't know if I just missed how to do it or it wasnt mentioned
How can I limit the items, like only keep adding 1 til I reach 9 after that then it stops ?
thanks man, great tutorial!
How did you learn all of this btw? I like your way of explaining the syntax. Very helpful.
Rene Hupfer A good place to start would be the help file included with Game Maker (by pressing F1) and look through its contents. You can also take a look at the built-in tutorials for Game Maker Studio. From the Welcome screen, click on the Tutorials tab and select which tutorial you'd like to do. You may have to download and install them, but this is an easy fix by right clicking the tutorial and then click on Install.
+HeartBeast I made a video showing you through the stages on how to add this to the GUI layer, am I allowed to post the link?
how to do that if collide with particular object player is gonna pick a particular item and how to equip
Thank you for the video
I just found (with some help) one major problem that I had. I had my inventory object named as obj_inventory where as Heartbeast just named his inventory. I was wondering why inventory showed up red in his code and white in mine, It wasn't registering in my brain. I had to go back through all of the code and change "inventory" to "obj_inventory" So be mindful of what your inventory object is named.
Omg man, i didnt know that inventory will be so hard to write. Thanks for this simply tutorial how to get powerfull eqipment in my game. (this is my first inventory i ever made... copied :D)
aparently the sword and bomb only show up if I make the inventory 8x8 (I origonally edited it to be 8wide and 1 tall ????
My mouse clicks are misaligned with adding/removing inventory objects, by exactly half of the x and y values of the boxes. I'm not sure how, I believe I followed every line of his code to the letter. Really bothering me that I can't figure it out.
Awesome as usual Ben :)
Trying to get this inventory to work in a draw gui event has been completely hopeless for me. I've read every comments that has anything to do with this problem to no avail. Can anybody help?
Ben is taking a while to upload a inventory tutorial to his RPG series. So can I use this one?
~Bork
how do you get this to work with a key press such as pressing i opens the inventory
I am getting error:
draw_sprite argument 2 incorrect type (5) expecting a Number (YYGI32)
at gml_Object_obj_inventory_DrawEvent_1 (line 7) - draw_sprite(spr_items, box[# xx, yy], tx, ty);
Does anyone know why this might be happening? It seems like a few other people are encountering the same error.
I got the exact same message. I don't know how to fix it, but i tried changing the names of the variables and it didn't do anything. So yeah. It's not that.
I know it's the box[# xx, yy] causing problems, but that's about it.
try to put string() around the box[# xx, yy]
i got the same error: i think when you copied the line four in (draw event): "for (xx = 0; xx < width; xx++){}", you forgot to change some of the arguments in line three: "for (yy = 0; yy < height; yy++) {}"
i hope it help's you out
very very good !!!
Are you participating in ludum dare?
How would you make this work with a controller? I want to use xbox one controller D-pad to control the inventory eg. cycle through ect.. Does anyone have any suggestions?
Nice video but you should have a video implementing this into an RPG game
ok I fixed part of it I now have 4 potions but still nothing else??
Is there a way to possibly do this in game maker 8.1?
I'm getting an out of bounds error:
Grid 1, index out of bounds writing [4,3] - size is [4,4]
Whenever I click outside the grid. I learned grid 1 is the count grid, and it was giving me an issue right here:
///Add a Random Item to the Inventory
var gx = x_to_gx(mouse_x);
var gy = y_to_gy(mouse_y);
var add_item = choose(minor_heal_pot[?'sprite'],minor_rez[?'sprite'],weak_axe[?'sprite'],metal_shield[?'sprite'],cloth_shoes[?'sprite']);
if(count[#gx,gy]==0)
{
inventory_add_item(gx,gy,add_item);
}
else
{
count[#gx,gy]++;
}
Since the out of bounds debugging is inside the add_item script, its kicking me out of my game. I found a bootleg workaround, but is there a more elegant solution to sorting this out?
HeartBeast has the same thing I have (unless I've missed something) and he gets his debugging message and does not get kicked out when he clicks outside of his grid.
Anyone got any ideas?
the same problem
thank you for gamemaker tutorial
This tutorial helped me alot with what I am aiming for! Thanks! I have one quick question about the stacking. I added a stack limit for the items, set it to stop counting on 999 and add a new stack in the next free slot. That works fine. but now I'm wondering how I can disable the stack for certain item groups, like swords and armor. It is a bit tedious to say
if (add_item != item.sword && add_item != item.shield && etc....) I can't figure it out :/
Nevermind :p managed to fix it by saying if (add_item
Would you mind explaining where/how you set up the stack limit? I'm way out of my depth here, I feel.
Inside the scr_pickupItem
for (var yy = 0; yy < obj_inventory.slotH; yy++) {
for (var xx = 0; xx < obj_inventory.slotW; xx++) {
var item_count = obj_inventory.itemCount[# xx,yy];
if (obj_inventory.invSlots[# xx,yy] == add_item && item_count < item_maxCount && add_item
Cheers - appreciate it! I should be able to puzzle it out from here. :)
... and got it! Once again, much appreciated!
Why not just set item count to 0 and set item to none if count is less than 0? Player won't lose anything (having something negative is bad anyway) and bug will fix itself if it ever happens.
13:55
How to add an item to the first empty slot with "pickup item" script ?
Yeah after I completed this tutorial my character disappeared... I think I might just re code the whole game, lol.
you need to draw the player object too if you used the player for the inventory drawing
use draw_self() inside the draw_event for the object of the player
Everything works just my grid dont get shown, i looked for 5 times every code and nothing found... rly need help
You do awesome tutorials, keep on doing this awesome stuff :)
Thx for answers and the tutorial
+Ghandi check your inventory_pickup_item, check loops in the script make sure if write xx++ and yy++
mine drew 5 potions and no bomb or sword???
Ur a f-in genius! THANK YOU
can someone explain the uses of box[# xx, yy] for me? I don't understand how draw_sprite(spr_item,box[# xx, yy], tx, ty) gives the image index needed or how draw_text(tx-1,ty-8,count[# xx , yy]) gives the correct string. If someone could explain it'd be really helpful because this is stopping me from fully understanding ds grids. thank you
+devin kelly Oke, I finally (because of this vid) understood the grid bullshit --
So,
let get the example: box[# xx, yy]
"box" is refering to the grid
the square bracket contain which "slot" of the grid needs to be accessed / changed etc.
Then I will try to make it as clear as posible (I am not the best at explaining... ) LET'S ADD AN ITEM
this is what you have in your script (add item)
///inventory_add_item(x, y, item)
var xx = argument[0];
var yy = argument[1];
var add_item = argument[2];
So, let me convert it step by step:
In you're code you would type this: inventory_add_item(3, 1, item.bomb)
the line above will add a bomb item in the x=3 and y=1 slot
[empty] - [empty] - [empty] - [empty]
[empty] - [empty] - [empty] - [BOMB]
[empty] - [empty] - [empty] - [empty]
[empty] - [empty] - [empty] - [empty]
This will be:
var xx = argument[0]; >>>>> var xx = 3;
var yy = argument[1]; >>>>> var yy = 1;
var add_item = argument[2]; >>>>> var add_item = item.bomb;
then if I refer to: box[# xx, yy] the xx is the x coordinate in the grid the yy the y coordinate
------------
draw_sprite(spr_item,box[# xx, yy], tx, ty)
It took me a while to figure this one out (thanks for commenting - it helped me understand too :) )
draw_sprite >>>> explains itself
spr_item >>>> same thing
box[# xx, yy] >>>> because of the "for statements" it will be all coordinates available in the grid. (line below)
box[# 0, 0] > box[# 0, 1] > box[# 0, 2] > box[# 0, 3] > box[# 1, 0] > box[# 1, 1] > box[# 1, 2] > ETC.
tx (and ty) are calculated like this: x+(xx*box_size)
x as the start position of the inventory object
xx as the slot number of the grid (x coordinate)
* box_size (so it knows how far in pixels it has to be drawn.
Oke, I think I explained it, but, I am not sure if this was your question, I'll try helping you if I was not clear :)
+devin kelly "#" is the accessor symbol for a grid in a data structure. It allows you to manipulate the grid as if it were a plain array, by adding the # to inform the engine it's a grid you're editing. Grids are really just 2D arrays.
Did you go to BYU? You look familiar.
The remove item wont work... i have no idea why all the code is exactly the same .-. anyone else having this or is it just me
How i can save this inventory and load? :D
is there a download for this so i can see the code without watching this video?
I wanna know how to save a dsgrid using ds map :(
Hey Ben, I'm wondering if I could make the inventory interactive but on the GUI layer. I can't figure it out, I've checked out your GUI buttons video but that isn't working :/ anyway this is possible?
+LiamDoesProgramming I have changed a few bits of code to make it sorta do this. It can only be placed in the top left hand corner though atm. Here are the changes -
x_to_gx - Replace inventory.x with view_xview[0]
y_to_gy - Replace inventory.y with view_yview[0]
inventory draw - (Swap to draw GUI)
inventory draw GUI - Replace var tx = x+(xx*box_size); with var tx (xx*box_size);
((Do same with y, obviously changing the x to y))
Hope this helps :)
+Electric Donkey thanks man! now time to make it more dynamic, I'm thinking about making a second view the size of the gui. That might work. Good programming! (idk lol)
+Electric Donkey I did this and it isn't working D:
+Electric Donkey I know it is half a year later, but thanks, it is working, now I need to figure out how to change it from the left top corner, but I think, I'll be able to :)
+Survival Gamer Oke, that was faily simple... just change:
var tx = (xx*box_size); to: var tx = (xx*box_size + 32);
(or what I did, change the 32 to a variable and change that in create event :)
EDIT:
and changing in x_to_gx:
(xx - view_xview[0]) to (xx - view_xview[0] - obj_inventory.inv_left_dist)
as inv_left_dist is my variable for the distance
Thank you~ Useful~
What language does this use, it looks lots like javascript to me with how it is written :P
+Kyanite Processing GML - GameMaker Language
This is crazeeeeyyy!!! xDDDDD THANKSS!!!
I could really use some help with some error messages that I have been receiving.
If someone could PM me that would be amazing.
Does anyone know how i can remove a specific item? like when i use a key i want only exact that item to disapear from inventory
+agge blue That should be quite easy. Just use 2 for loops to loop through every single box and check each box for the item, if it finds that item, use the remove script to get rid of it. If you need any help doing this private message me.
Electric Donkey I'm not experienced in gml and not sure where to use the for loop, if you don't mind helping me out on this i'd appriciate!
+agge blue
Hi, about the removing of a single item here is the code -
Add an event for the key you want to press then add this -
for(var xx = 0; xx < width; xx++) {
for(var yy = 0; yy < height; yy++) {
if(inventory.box[# xx, yy] = ((ITEM YOU WANT TO REMOVE)) {
inventory_remove_item(xx, yy);
}
}
}
That should work, if not, just say :)
Electric Donkey Thankyou! :-) works perfect
agge blue anytime ;)
i love you somuch
Is
This the first part to your rpg series ?
+alen tursunovic I thought his next tutorial series was gonna be a pokemon style game.
+VintageLJ which is an RPG :)
Kyanite Processing touche
haha, lol
What is wrong with this code. There's like 10 people asking about it here? Why do so many people have this error?
draw_sprite argument 2 incorrect type (5) expecting a Number (YYGI32)
at gml_Object_obj_inventory_DrawEvent_1 (line 11) - draw_sprite(spr_items, box[# xx, yy], tx, ty);
draw_sprite(spr_items, box[# xx, yy], tx, ty);
if (count[# xx, yy] > 0)
It means that the type of "box[# xx, yy] " is not correct. It may because that the coordinate of ds_grid is out of range, for example the grid size is 5*10 but your code try to get the value at [6,1](x is out of range). Try to swap the coordinate to box[# yy,xx] (or change the previous code about xx and yy). And it may also caused by the wrong value type of the ds_grid value, make sure that the enum variables have a number value. I hope it can help you.
Ah, such a simple mistake anyone can make but I see what you mean now. Thanks for figuring it out.
lol I use GM 8.0 pro and I don't need accessors.
Hey Heartbeast first of all thankyou for this awesome tutorial
AND i just wanted to ask
how can i make it so i whenever i remove an item it gets to dropped under the player's x, y? Becaus right now it's abit shame that the item just disapears ? D:
becaus if you need more inventory space to new items in ur game this could be useful
sorry if this is too much i just have no idea how to impliment this
For anyone that wants the inventory to follow with views. All you have to do is edit the inside the *x_to_gx* likethis: *if (xx < Inventory.view_xview[0]) return -1;*
*return (yy - Inventory.view_yview[0]) div Inventory.box_size;* also remember to edit with *y_to_gy*
Also could you expand this tutorial abit. I have some ideas to what could be inside the tutorial, maybe make it so whenever you reach a max item stack, like in minecraft 64 then it goes to the next slot. And if possible make it so you can drag the item like in diablo and drop it on the ground same with putting inside the inventory? Just some ideas
+agge blue I'm afraid this code for the x_to_gx doesn't work. However, I do know how to make items reach max items. Make these changes -
inventory_add_item -
In add one to the count add this - if(obj_inventory.count[# xx, yy] < 10) { ((Replace 10 with whatever item you want it to stop stacking at.))
You can also add an } else { in and put this in - show_message("That slot is full!");
obj_inventory.box[# global.box_x, global.box_y] = global.last_item
obj_inventory.count[# global.box_x, global.box_y]++;
return false;
This will say that the slot is full and then place it back in the previous slot. (make sure to set global.box_x and y to the previous box somewhere. Also global.last_item should equal the last item, if you need help setting these just ask :)
Electric Donkey Thank you for the replay i'll try it out!. as for the x_to_gx i forgot to mention also change the *draw event' to *draw GUI event*
+agge blue Even if you move it to a draw GUI event it doesn't work (mainly because x and y don't exist in the GUI) But even if you change the x and y in the draw GUI event to integers it still doesn't work. P.S. I am working on the dropping of items, however I have changed my inventory_remove/add_item a lot so may not work perfectly with the original code.
Electric Donkey it works for me not sure what i did to make it work, but if you want i can upload my project with inventory? also mind helping me out on the dropping item system?:P
+agge blue If you could do that it would be massively appreciated! I can help you with the dropping of items although I fear it would be too complicated to explain over the comments, I can guide you through it in private chat/ messaging on youtube however.
PLEASE help
this has been going on for a LONG time
whenever i try to read my sign it senses the dash key so fast that it just makes it unreadable
HELP!
+Allen LaneTM What do you mean by that? read your sign? what dign? this is an inventory tutorial..
Survival Gamer
It is not referencing this video but another one by him
+Allen LaneTM which video?could you link it? I'll watch it, and I'll try to help you after, :)
+Allen LaneTM which video?could you link it? I'll watch it, and I'll try to help you after, :)
I need to find a inventory system that isn't a pain in the neck to implement new items
Citrix killed my family.
anybody know how to make an item NOT STACK?
i will tell you but if you can help me, My inventory object isnt drawing the rest of my objects and clicking with the mouse adds the item id first then the add 1
put the code or files for the inventory object and the scripts the next ccomment
i will tell you then
never mind fixedit!!
I do know how to make items reach max items. Make these changes -
inventory_add_item -
In add one to the count add this - if(obj_inventory.count[# xx, yy] < 10) { ((Replace 10 with whatever item you want it to stop stacking at.))
You can also add an } else { in and put this in - show_message("That slot is full!");
obj_inventory.box[# global.box_x, global.box_y] = global.last_item
obj_inventory.count[# global.box_x, global.box_y]++;
return false;
This will say that the slot is full and then place it back in the previous slot. (make sure to set global.box_x and y to the previous box somewhere. Also global.last_item should equal the last item, if you need help setting these just ask
OOOOOOOOOOOOORRRRRRRRRRRRR
this is more simple
This is his pickup script ( I think that is the most needed one with max items per slot)
// Check for item in inventory
for (var yy = 0; yy < obj_inventory.height; yy++) {
for (var xx = 0; xx < obj_inventory.width; xx++) {
if (obj_inventory.box[# xx, yy] == add_item) {
obj_inventory.count[# xx, yy]++
return true;
}
}
}
Simply add 1 line of code to make your work become real
if obj_inventory.count[# xx, yy] < 8 {
*So that would make: *
// Check for item in inventory
for (var yy = 0; yy < obj_inventory.height; yy++) {
for (var xx = 0; xx < obj_inventory.width; xx++) {
if (obj_inventory.box[# xx, yy] == add_item) {
if obj_inventory.count[# xx, yy] < 8 {
obj_inventory.count[# xx, yy]++
return true;
}
}
}
}
So... how can you pick up items by walking over? ... i don't really get it..
Here's my code (Step: obj_item_note1)
var gx = x_to_gx(x);
var gy = y_to_gy(y);
var add_item = obj_item_note1;
if (point_distance(x,y,obj_player.x,obj_player.y) < 64)
{
move_towards_point(obj_player.x,obj_player.y,4);
if (point_distance(x,y,obj_player.x,obj_player.y) < 2)
{
instance_destroy();
inventory_add_item(gx,gy,add_item);
}
}
+VAYNlion idk the answer but you can check gmc.yoyogames.com and ask there
+VAYNlion as far as I understand it should be:
This is my version I simply just typed it to test your thing out:
if distance_to_object(obj_player) < 32 {
inventory_pickup_item(item.bomb);
instance_destroy();
}
in your case it should be a note - so, add a note to the spr_items
in the inventory object add (in create event) (execute code (enum))
this should work fine
enum item {
none = 0,
potion = 1,
bomb = 2,
sword = 3,
note = 4
}
*Let's say you kept the sprites he used*
if you didn't you need to adjust the "4" above to whatever subimage you used...
+Survival Gamer try that with place_meeting :D
add a colision event, and then make it add an item to the inventory, then deystroy the item (instance_destroy();)
But. How can i use crafting with that?
Very good content, but do not answer emails.
Still living in the attic huh?
This for what?
Igramania what?
Just wasted 50 of my life
You should be more careful what you watch... ;)
HeartBeast sorry I was just salty because I wasted 40 min just to find out it didn't work for my game 😖
Oh darn. Yeah that sucks. This should work in about any game, though. Which type of game are you making?
HeartBeast it's an RPG. But in this is for games where u can see the whole map and not for games where u walk around with the cam following u. It's probably easy to change it, but I have never worked with a grid before
Heartbeast how do I make a limit to how many per inventory slot?
+Arthod GDT Hey, you probably don't mind, me helping you :)
This is his pickup script ( I think that is the most needed one with max items per slot)
// Check for item in inventory
for (var yy = 0; yy < obj_inventory.height; yy++) {
for (var xx = 0; xx < obj_inventory.width; xx++) {
if (obj_inventory.box[# xx, yy] == add_item) {
obj_inventory.count[# xx, yy]++
return true;
}
}
}
*Simply add 1 line of code to make your work become real*
if obj_inventory.count[# xx, yy] < 8 {
*So that would make: *
// Check for item in inventory
for (var yy = 0; yy < obj_inventory.height; yy++) {
for (var xx = 0; xx < obj_inventory.width; xx++) {
if (obj_inventory.box[# xx, yy] == add_item) {
if obj_inventory.count[# xx, yy] < 8 {
obj_inventory.count[# xx, yy]++
return true;
}
}
}
}
I got it figured out, but thanks alot for helping me though
+Arthod GDT Maybe you can help me out with an error, I am kinda stuck... so this is the error message I get when left clicking outside my inventory:
FATAL ERROR in
action number 1
of Mouse Event for Glob Left Pressed
for object obj_inventory:
DoAdd :2: undefined value
at gml_Object_obj_inventory_GlobalLeftButtonPressed_1 (line 12) - count[# gx, gy]++;
In this file:
/// Add a random item to the inventory
var gx = x_to_gx(mouse_x);
var gy = y_to_gy(mouse_y);
var add_item = choose(item.potion, item.bomb, item.sword);
if (count[# gx, gy] == 0) {
inventory_add_item(gx, gy, add_item);
} else {
count[# gx, gy]++;
}
I searched up:
DoAdd:: Execution Error
Something has gone wrong when using the addition (+) expression.
When he clicks next to it it just says, outside borders, what means that his script started (inventory_add_item) - after some testing I kinda know for sure it didn't start the script... And I don't know why
(I named mine: obj_inventory instead of Inventory)
I am not sure. But try to make it: "Inventory.count(# gx, gy]++" instead of it being without: "Inventory."
+Arthod GDT I tried that, gave the same error message, I am going to see if I can find the solution, Thanks anyway!!!