# Lua aray problem [closed]

I'm working on a game but Im havin a bit of a problem. The problem is for example if i buy 1 ham it charges 55 gold and I get 1 ham but if I want 5 ham I get 5 ham but it only charge 55 gold when it should charge 275 gold.

``````_state = 0
_count = 0
_index = 0

-- List of items you can buy
items = {}
items[0] = {name = 'ham', id = 456, price = 55}
items[1] = {name = 'fish', id = 201, price = 60}
items[2] = {name = 'mushroom', id = 355, price = 150}
items[3] = {name = 'bread', id = 356, price = 10}
``````

The Function

``````local function onActionItem(action)

amount = ''
suffix = ''
plural = 'a'

if (_count > 1) then
amount = ' ' .. tostring(_count)
suffix = 's'
plural = ''
end

cost = items[_index].price

selfSay('Do you want to buy ' .. plural .. amount .. ' ' .. items[_index].name .. suffix .. ' for ' .. cost .. ' gold?', 1000)
end
``````
-
Your question is off-topic in this site, we strictly improve working code. –  Winston Ewert Aug 8 '12 at 15:40

## closed as off topic by Winston EwertAug 8 '12 at 15:40

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

You've missed off using _count in the cost

``````cost = items[_index].price * _count
``````

You also have some tidying up to do with spaces "Do you want to buy5 hams" - two spaces between buy and 5.

For completeness, you'll need extra work on plurals - fish -> fishes, and you want "loaf of bread" (-> loaves of bread) as an item. You may be better off extending the items array to include the plural name rather than assembling it.

-
doh! thx! yes youre right "breads" and "fishs" wont be so popular haha –  tomek Aug 1 '12 at 16:16
``````cost = items[_index].price
``````cost = items[_index].price * _count