Difference between revisions of "Organize Inventory Items Alphabetically (CMS)"
From The Official Visionaire Studio: Adventure Game Engine Wiki
Line 31: | Line 31: | ||
function invSort(val) | function invSort(val) | ||
− | if val then order = function( a,b ) return a:getName() < b:getName() end | + | -- + ascending sort function (A-Z, 1-9) + -- |
− | + | if val then order = function( a,b ) return a:getName() < b:getName() end | |
+ | -- + descending sort function (Z-A, 9-1) + -- | ||
+ | else order = function( a,b ) return a:getName() > b:getName() end end | ||
return order | return order | ||
end | end |
Revision as of 15:59, 12 February 2014
Name | Type | By |
---|---|---|
Organize Inventory Items Alphabetically | Definition | AFRLme |
This script allows you to organize your inventory items alphabetically in either ascending or descending order.
Instructions
1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. To organize the inventory items by ascending order, you should create an execute a script action containing:
arrangeItems(true)
3. To organize the inventory items by descending order, you should create an execute a script action containing:
arrangeItems(false)
Main Script
--[[
Organize Items Alphabetically (v2) [12/02/2014]
By AFRLme
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
--]]
local char, items, order -- empty variables
function invSort(val)
-- + ascending sort function (A-Z, 1-9) + --
if val then order = function( a,b ) return a:getName() < b:getName() end
-- + descending sort function (Z-A, 9-1) + --
else order = function( a,b ) return a:getName() > b:getName() end end
return order
end
function arrangeItems(val)
char = game:getLink(VGameCurrentCharacter) -- store current character
items = char:getLinks(VCharacterItems) -- store items
table.sort(items, invSort(val)) -- sort the items alphabetically
char:setValue(VCharacterItems, items) -- amend new item order to the inventory
end