Difference between revisions of "LangVisibility (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "{| class="ts" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | langVisibility(duration, easing) ||...")
 
m
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
  
 
This small function allows you to quickly adjust the visibility of all scene objects containing language names in them.
 
This small function allows you to quickly adjust the visibility of all scene objects containing language names in them.
 +
<hr>
 +
{| class="ts"
 +
|-
 +
| ''Quick note: this function is slow & should only be called at begin of scene if the scene is faded in & not shown immediately; other than that feel free to use it however you like.
 +
|}
 +
<hr>
  
  
 
== Instructions ==
 
== Instructions ==
 
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. Usage example: immediately update the visibility of all scene objects containing the name of the current language in them to 100%; set objects with other language names to 0%.
+
2a. Usage example #1: immediately update visibility of all objects containing active language name to 100%; set objects with other language names to 0%.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
langVisibility()
 
langVisibility()
 +
</syntaxhighlight>
 +
2b. Usage example #2: update visibility over 1000ms for all objects containing active language name to 100%; set objects with other language names to 0%.
 +
<syntaxhighlight lang="lua">
 +
langVisibility(1000)
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Latest revision as of 23:24, 23 August 2022

Name Type By
langVisibility(duration, easing) Definition AFRLme

This small function allows you to quickly adjust the visibility of all scene objects containing language names in them.


Quick note: this function is slow & should only be called at begin of scene if the scene is faded in & not shown immediately; other than that feel free to use it however you like.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Usage example #1: immediately update visibility of all objects containing active language name to 100%; set objects with other language names to 0%.

langVisibility()

2b. Usage example #2: update visibility over 1000ms for all objects containing active language name to 100%; set objects with other language names to 0%.

langVisibility(1000)


Main Script

local obj = {} -- init obj table

function langVisibility(duration, easing)
  duration = duration or 0 -- fallback in case duration equals nil
  easing = easing or easeLinearInOut -- fallback in case duration equals nil
  obj = game.CurrentScene.Objects -- store current scene objects
  -- + --
  for i = 1, #obj do -- iterate through the current scene objects table
    for a = 1, #game.Languages do -- iterate through language tables
      if string.find( string.lower( obj[i]:getName() ), string.lower( game.Languages[a]:getName() ) ) then -- language found
        if game.StandardLanguage == game.Languages[a] then -- language is current language
          obj[i]:to(duration, {Visibility = 100}, easing) -- set visibility of currently listed scene object to 100%
        else -- language is not current language
          obj[i]:to(duration, {Visibility = 0}, easing) -- set visibility of currently listed scene object to 0%
        end
      end
    end
  end
end


Syntax Breakdown

Name Type Description
duration integer This should contain a number value in milliseconds of how long you want the visibility to take to change from the current value to the target value.
easing integer This should contain a number value, or the variable name of the easing type that you want to use. Here is a list of available easing options.