Inventory and equipment inventory help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Inventory and equipment inventory help
Adventually I would like to make an mmorpg or just an rpg game. I honestly have no clue how to make an inventory or equipment inventory atm i dont really care about the equipment inventory just getting the system to work is what i would like. In C++ you would use arrays so would i use a table.
Im confused can someone please give a detailed answer.
Thanks its appriciated
Im confused can someone please give a detailed answer.
Thanks its appriciated
Re: Inventory and equipment inventory help
The concept of an Inventory is very high level and difficult to explain, so it's necessary to break it down into a few parts:
First is the actual storage of the data that represents the inventory. If it's just a straight list of items, then this is trivial in Lua: use a table with integer keys. If you want to be a bit more OOP about it, use Lua's sugar syntax.
Of course, that code is a bit silly, it's just for demonstration purposes.
Second, you need a way to view that inventory. That's where it can get a bit complex, because you need to draw those items in some capacity. I can give another silly example:
Third, you need a way to do something with that inventory, like move the items around. Here's another silly example:
Officially, these three pieces of the system you want are called the "Model", "Viewer", and "Controller". If you combine them into a main.lua and test it in love, it should be a working demo. Obviously, to make a bigass RPG or MMORPG, you have a lot of work ahead of you.
First is the actual storage of the data that represents the inventory. If it's just a straight list of items, then this is trivial in Lua: use a table with integer keys. If you want to be a bit more OOP about it, use Lua's sugar syntax.
Code: Select all
inventory = {}
function inventory:get( index )
return self[index]
end
function inventory:set(index, value)
self[index] = value
end
function inventory:swap( first, second )
self[first], self[second] = self[second], self[first]
end
MAX_INVENTORY = 20
inventory:set( 1, "Potion" )
inventory:set( 2, "Tent" )
Second, you need a way to view that inventory. That's where it can get a bit complex, because you need to draw those items in some capacity. I can give another silly example:
Code: Select all
item_highlighted = 1
function love.draw()
love.graphics.setColor( 255, 255, 255 )
for i = 1, MAX_INVENTORY do
local item = inventory:get(i)
if type(item)=="string" then
love.graphics.print( item, 20, 10*(i-1) )
end
end
if item_selected then
love.graphics.rect( "fill", 8, 10*(item_selected-1), 10, 10 )
love.graphics.setColor( 255, 255, 0 )
end
love.graphics.rect( "fill", 8, 10*(item_highlighted-1), 10, 10 )
end
Code: Select all
function love.keypressed(k)
if k == "up" then
if item_highlighted > 1 then
item_highlighted = item_highlighted - 1
end
elseif k == "down" then
if item_highlighted < MAX_INVENTORY then
item_highlighted = item_highlighted + 1
end
elseif k == "return" then
if item_selected then
inventory:swap( item_selected, item_highlighted )
item_selected = nil
else
item_selected = item_highlighted
end
end
end
Re: Inventory and equipment inventory help
thanks but i still ahve 1 question. Say i were to have a player and if he collides with an item how wud i make it so the item gets picked up.
Oh and how will i set each index to a different image is there an easier way then just doing
inventory[1] = love.graphics.newImage("images/apple.png")
is there an easier way?
Oh and how will i set each index to a different image is there an easier way then just doing
inventory[1] = love.graphics.newImage("images/apple.png")
is there an easier way?
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Inventory and equipment inventory help
Fairly simple...You may have a boolean stating if the object was taken or not.coke905 wrote:thanks but i still ahve 1 question. Say i were to have a player and if he collides with an item how wud i make it so the item gets picked up.
When the player collides with that object, set this boolean to false, undraw it, and move it the array of objects that the player owns.
That's a way, yet there are plenty others. Truth is, there is no specific algorithm for that purpose, just do it your way.
Yes, there is. And it depends.coke905 wrote: Oh and how will i set each index to a different image is there an easier way then just doing
inventory[1] = love.graphics.newImage("images/apple.png")
is there an easier way?
If your images are named in a specific sequence, you could make use of it.
Using a for loop and concatenation operator.
Code: Select all
-- Assuming they are named 1.png, 2.png, 3.png
-- n must be defined!
for i = 1,n do
inventory[i] = love.graphics.newImage(i .. '.png')
end
-- Or Assuming they are named image1.png, image2.png
-- n must be defined!
for i = 1,n do
inventory[i] = love.graphics.newImage('image'.. i .. '.png')
end
Alternatively, you can load all images inside a folder to a table.(That's a bit rough, but fairly doable)
They will be indexed with with string corresponding to their names.
Code: Select all
local imageFolder = 'images/' --Path to your images folder
local images = love.filesystem.enumerate (imageFolder)
local inventory = {}
for i,imageRelativePath in ipairs(images) do
local imageName = (imageRelativePath:gsub('.%a+$',''))
inventory[imageName] = love.graphics.newImage(imagesFolder .. imageRelativePath )
end
Re: Inventory and equipment inventory help
LOL thats extremely confusing. Can you make a youtube video tutorial or something, i seem to learn better with videos.
If you dont know a good free camera program to use type in "hypercam2".
I'm new and what you wrote there is just confuzzling me (LOLZ) anyways can someone make a video on it or try to explain it like your telling a grade 7er.
thanks
If you dont know a good free camera program to use type in "hypercam2".
I'm new and what you wrote there is just confuzzling me (LOLZ) anyways can someone make a video on it or try to explain it like your telling a grade 7er.
thanks
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Inventory and equipment inventory help
Making a video for such a snippet is pointless.
And you're not gonna have each time a video to help you understand things you don't get.
Just ask, afterall, threads are meant for that, I guess.
And you're not gonna have each time a video to help you understand things you don't get.
Just ask, afterall, threads are meant for that, I guess.
Re: Inventory and equipment inventory help
Actually the snippets presented here are of quite low complexity, relative to some operations performed in game code. I would suggest that if you cannot understand these examples you should seek some basic game development (and design) articles.coke905 wrote:LOL thats extremely confusing. Can you make a youtube video tutorial or something, i seem to learn better with videos.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Re: Inventory and equipment inventory help
Oh I'm sorry and I have read on google and I have tried sublime text text plus plus and way more. I know this is how I normally respond but I've been experimenting with inventory but I'm stuck on adding a strength variable to each index.
Function inventory:set(id, index, str)
self[id] = index
end
with the str perimeter I'd like to set the strength value of each id. I'm extremely sorry for wasting ur guys time I'll start looking way more into things before I post anything.
Function inventory:set(id, index, str)
self[id] = index
end
with the str perimeter I'd like to set the strength value of each id. I'm extremely sorry for wasting ur guys time I'll start looking way more into things before I post anything.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Inventory and equipment inventory help
I'm not sure i caught was your problem was, but I'll suggest letting the item located a position "id" in the inventory be a table.coke905 wrote:Oh I'm sorry and I have read on google and I have tried sublime text text plus plus and way more. I know this is how I normally respond but I've been experimenting with inventory but I'm stuck on adding a strength variable to each index.
with the str perimeter I'd like to set the strength value of each id. I'm extremely sorry for wasting ur guys time I'll start looking way more into things before I post anything.Code: Select all
Function inventory:set(id, index, str) self[id] = index end
This way, you can store anything you want inside.
Code: Select all
Function inventory:set(id, index, str)
self[id] = { index = index, strength = str}
end
And by the way,
function must not be capitalized, as Lua is case-sensitive, Function does not refer to the keyword which declares functions, function.coke905 wrote:Function inventory:set(id, index, str)
May be a typo error, but just wanted to point it out.
Re: Inventory and equipment inventory help
Thanks ooh and I know it can't be capitalized on my iPod everytime u have a new line it automatically goes to caps
Who is online
Users browsing this forum: Bing [Bot] and 3 guests