Difference between revisions of "Organize Inventory Items Alphabetically (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(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...")
 
Line 28: Line 28:
 
--]]
 
--]]
  
local char, items -- empty variables
+
local char, items, order -- empty variables
local sort_func = function( a,b ) return a:getName() < b:getName() end -- sort function (ascending A-Z, 1-10 etc)
 
  
function arrangeItems()
+
function invSort(val)
 +
if val then order = function( a,b ) return a:getName() < b:getName() end end -- sort function (ascending A-Z, 1-10 etc)
 +
if not val then order = function( a,b ) return a:getName() > b:getName() end end -- sort function (descending Z-A, 10-1 etc)
 +
return order
 +
end
 +
 
 +
function arrangeItems(val)
 
  char = game:getLink(VGameCurrentCharacter) -- store current character
 
  char = game:getLink(VGameCurrentCharacter) -- store current character
 
  items = char:getLinks(VCharacterItems) -- store items
 
  items = char:getLinks(VCharacterItems) -- store items
  -- * add each item into a table; one at a time * --
+
  table.sort(items, invSort(val)) -- sort the items alphabetically
print("-- * before * --")
+
  char:setValue(VCharacterItems, items) -- amend new item order to the inventory
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
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
 
{{i18n|Organize_Inventory_Items_Alphabetically_(CMS)}}
 
{{i18n|Organize_Inventory_Items_Alphabetically_(CMS)}}

Revision as of 15:50, 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)
 if val then order = function( a,b ) return a:getName() < b:getName() end end -- sort function (ascending A-Z, 1-10 etc)
 if not val then order = function( a,b ) return a:getName() > b:getName() end end -- sort function (descending Z-A, 10-1 etc)
 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