Hello, I am working on a game and I want to have it so that when you mouse over an item in your inventory, it tells you what it is. Currently, I have all the items in the Inventory as drawables. ex. Inventory.item[1] = Stone (stone is a drawable). I think I need to move away from this system and find a different way to store the information, but I am not sure which way I should do this. Should I have the items be just a name and have a table with the images for it? ex.
Images[Stone] = love.graphics.newImage("Stone.png)
Inventory.item[1] = Stone
love.graphics.draw(Images[Inventory.item[1]]
of should I somehow create a Stone object and attach a drawable to it? Thank you!
Help turning a drawable name into a string.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 21
- Joined: Wed Apr 15, 2015 10:51 pm
Re: Help turning a drawable name into a string.
Code: Select all
print(tostring(Inventory.item[1]))
Code: Select all
images[stone].name = "stone"
print(Inventory.item[1].name)
-
- Prole
- Posts: 21
- Joined: Wed Apr 15, 2015 10:51 pm
Re: Help turning a drawable name into a string.
tostring just printed "image", but I am working on the second option. Thank you!
Re: Help turning a drawable name into a string.
Haha whoops yeah.
That's what i get for providing help at 5 am in the morning >_>
That's what i get for providing help at 5 am in the morning >_>
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Help turning a drawable name into a string.
In your exemple, Stone, is a variable that has not be defined yet, not a string variable.
When you do:
(firstly, you'll get an error because you forgot a " in the end of "Stone.png, this is the correct way of doing this:)
Secondly, if you don't define the variable Stone then that is the same way as writing this:
And you'll get an error saying that you can't index a nil value, so you probably want to do this:
You have to put Stone inside "", this way Lua will interpert Stone as a string and not as a variable.
Or you could define the variable Stone first, like so:
After that what, you'll want to do to save the name of the item is to write the string "Stone" into your item table:
or:
When you do:
Code: Select all
Images[Stone] = love.graphics.newImage("Stone.png)
Code: Select all
Images[Stone] = love.graphics.newImage("Stone.png")
Code: Select all
Images[nil] = love.graphics.newImage("Stone.png")
Code: Select all
Images["Stone"] = love.graphics.newImage("Stone.png")
Or you could define the variable Stone first, like so:
Code: Select all
Stone = "Stone" --variable Stone in a string variable containing the string "Stone"
Images[Stone] = love.graphics.newImage("Stone.png")
Code: Select all
Inventory.item[1] = "Stone"
Code: Select all
Stone = "Stone"
Inventory.item[1] = Stone
Who is online
Users browsing this forum: Google [Bot] and 2 guests