Chapter 11: Page 199 - 'Sorting the Player's Inventory'
In this section, the function itemNameSort
should really be called compareItemName
and the text should be updated to reflect this. The implementation of the function should be as follows:
function compareItemName(a, b)
if a.name < b.name then
return true
else
return false
end
end
While this code is equivalent to the existing itemNameSort
definition, the concepts of custom comparison functions introduced in Chapter 5 should be reinforced here. The name of the function was confusing, and it was not clear enough in the shorter example what the function was actually doing.