Organize Inventory Items Alphabetically (CMS)

From The Official Visionaire Studio: Adventure Game Engine Wiki
Revision as of 16:48, 12 February 2014 by AFRLme (talk) (Created page with "{| class="wikitable" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | Organize Inventory Items Alp...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 -- empty variables
local sort_func = function( a,b ) return a:getName() < b:getName() end -- sort function (ascending A-Z, 1-10 etc)

function arrangeItems()
 char = game:getLink(VGameCurrentCharacter) -- store current character
 items = char:getLinks(VCharacterItems) -- store items
 -- * add each item into a table; one at a time * --
 print("-- * before * --")
 for i = 1, table.maxn(items) do print(items[i]) end 
 -- * sort the items alphabetically * --
 table.sort(items, sort_func)
 print("-- * after * --")
 for i = 1, table.maxn(items) do print(items[i]); end
 -- * amend the new item list to the current character * --
 char:setValue(VCharacterItems, items)
end