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...")
 
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{| class="wikitable" style="width:100%"
+
{| class="ts" style="width:100%"
 
|-
 
|-
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| Organize Inventory Items Alphabetically || Definition || AFRLme
+
| Organize Inventory Items Alphabetically || Definition || [https://www.patreon.com/AFRLme AFRLme]
 
|}
 
|}
  
Line 11: Line 11:
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
2. To organize the inventory items by ascending order, you should create an ''execute a script'' action containing:
 
2. To organize the inventory items by ascending order, you should create an ''execute a script'' action containing:
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
arrangeItems(true)
 
arrangeItems(true)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
3. To organize the inventory items by descending order, you should create an ''execute a script'' action containing:
 
3. To organize the inventory items by descending order, you should create an ''execute a script'' action containing:
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
arrangeItems(false)
 
arrangeItems(false)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
 
--[[
 
--[[
Organize Items Alphabetically (v2) [12/02/2014]
+
Organize Items Alphabetically [v2] (12/02/2014)
By AFRLme
+
Written by AFRLme [Lee Clarke]
 
-- + --
 
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
+
email: afrlme@outlook.com
 +
paypal: afrlme@zoho.com
 +
patreon: https://www.patreon.com/AFRLme
 +
portfolio: https://afrl.me
 +
-- + --
 +
This script is donation optional. In game credit is non-negotiable.
 +
You are free to: ¹ use it in your game(s). ² modify the script.
 +
Do not remove - or edit - this comment block.
 
--]]
 
--]]
  
local char, items -- empty variables
+
-- * local variables * --
local sort_func = function( a,b ) return a:getName() < b:getName() end -- sort function (ascending A-Z, 1-10 etc)
+
local char, items, asc, desc -- empty variables
 +
 
 +
-- * function for toggling between ascending & descending order * --
 +
function invSort(val)
 +
asc = function( a,b ) return a:getName() < b:getName() end -- ascending (A-Z, 1-9)
 +
desc = function( a,b ) return a:getName() > b:getName() end -- descending (Z-A, 9-1)
 +
if val then return asc else return desc end
 +
end
  
function arrangeItems()
+
-- * function for updating inventory items alphabetically * --
 +
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>{{toc}}
{{i18n|Organize_Inventory_Items_Alphabetically_(CMS)}}
 

Latest revision as of 14:27, 15 September 2022

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)
Written by AFRLme [Lee Clarke]
-- + --
email: afrlme@outlook.com
paypal: afrlme@zoho.com
patreon: https://www.patreon.com/AFRLme
portfolio: https://afrl.me
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * local variables * --
local char, items, asc, desc -- empty variables

-- * function for toggling between ascending & descending order * --
function invSort(val)
 asc = function( a,b ) return a:getName() < b:getName() end -- ascending (A-Z, 1-9)
 desc = function( a,b ) return a:getName() > b:getName() end -- descending (Z-A, 9-1)
 if val then return asc else return desc end
end

-- * function for updating inventory items alphabetically * --
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