<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.frozenbyte.com/index.php?action=history&amp;feed=atom&amp;title=Helpful_Lua_Snippets</id>
	<title>Helpful Lua Snippets - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.frozenbyte.com/index.php?action=history&amp;feed=atom&amp;title=Helpful_Lua_Snippets"/>
	<link rel="alternate" type="text/html" href="https://wiki.frozenbyte.com/index.php?title=Helpful_Lua_Snippets&amp;action=history"/>
	<updated>2026-05-16T14:01:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://wiki.frozenbyte.com/index.php?title=Helpful_Lua_Snippets&amp;diff=284&amp;oldid=prev</id>
		<title>AnteroFB: Created page with &quot; This page aims at sharing helpful samples of code you might have written while creating your mods. Any help is welcome.  Please use the same templates for each snippet.  == G...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.frozenbyte.com/index.php?title=Helpful_Lua_Snippets&amp;diff=284&amp;oldid=prev"/>
		<updated>2018-06-15T08:15:36Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; This page aims at sharing helpful samples of code you might have written while creating your mods. Any help is welcome.  Please use the same templates for each snippet.  == G...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
This page aims at sharing helpful samples of code you might have written while creating your mods. Any help is welcome.&lt;br /&gt;
&lt;br /&gt;
Please use the same templates for each snippet.&lt;br /&gt;
&lt;br /&gt;
== Getting Player object ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function getCharacter()&lt;br /&gt;
        local instanceManager=common.CommonUtils.getSceneInstanceManager()&lt;br /&gt;
	local cm = instanceManager:findInstanceByName(&amp;quot;TrineCharacterSelectionManagerInst&amp;quot;)&lt;br /&gt;
	local character = cm:getCharacterInstanceForPlayer(0)&lt;br /&gt;
	return character &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;What it does&amp;#039;&amp;#039;: Get the object representing the player&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Parameters&amp;#039;&amp;#039;: None&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Editor version&amp;#039;&amp;#039;: v2&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardA-L|LeonardA-L]] ([[User talk:LeonardA-L|talk]]) 12:06, 15 March 2015 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Change object position ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function shift(object, dx,dy,dz)&lt;br /&gt;
	local toShift = object:getTransformComponent()&lt;br /&gt;
	local vec = VC3(dx,dy,dz)&lt;br /&gt;
&lt;br /&gt;
	toShift :setPosition(toShift :getPosition()+vec)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;What it does&amp;#039;&amp;#039;: Shifts an objects model&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Parameters&amp;#039;&amp;#039;:&lt;br /&gt;
* Object: the object to shift&lt;br /&gt;
* dx,dy,dz: displacement values (float) for the x,y and z axis&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardA-L|LeonardA-L]] ([[User talk:LeonardA-L|talk]]) 12:06, 15 March 2015 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Display text ==&lt;br /&gt;
Couldn&amp;#039;t find an Entity to display text on screen, so I adapted from gui.debug.formattedText.&lt;br /&gt;
Can easily be tweaked to have your own text as parameter, or update a previously created text.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
textWindowToggled = false&lt;br /&gt;
&lt;br /&gt;
-- testing the creation utils...&lt;br /&gt;
function createTextWindow()	&lt;br /&gt;
	if (textWindowToggled) then&lt;br /&gt;
		textWindowToggled = false&lt;br /&gt;
		&lt;br /&gt;
		gui.WindowUtils.deleteWindow(testWindowCenter)&lt;br /&gt;
		testWindowCenter = nil&lt;br /&gt;
	else&lt;br /&gt;
		textWindowToggled = true&lt;br /&gt;
		&lt;br /&gt;
		local clickableInput = gui.menu.Menus.getWindowInputByName(&amp;quot;clickableOverlayInput&amp;quot;)&lt;br /&gt;
		&lt;br /&gt;
		-- Create a new window&lt;br /&gt;
		testWindowCenter = gui.WindowUtils.createWindowAnchoredToTopLeft(&amp;quot;CenteredTest&amp;quot;, clickableInput, -1, nil, 10, false, nil, true)&lt;br /&gt;
		gui.UI.stack:push(testWindowCenter.bottomWidget)&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
		local testText = [[ &amp;lt;b&amp;gt;Awesome!&amp;lt;/b&amp;gt; ]]&lt;br /&gt;
		-- Create text&lt;br /&gt;
		theFormattedText = gui.TextBoxUtils.createNonLocalizedFormattedTextBox(&amp;quot;MyTextBox&amp;quot;, &amp;quot;gray&amp;quot;, testText, true, gui.AlignmentUtils.getRightTopAlignment())&lt;br /&gt;
&lt;br /&gt;
		theFormattedText.widgetForClipper:setDock(engine.gui.DockFillWidth)&lt;br /&gt;
		theFormattedText.formattedText:setDock(engine.gui.DockFillWidth)&lt;br /&gt;
		&lt;br /&gt;
		-- Push to the created window&lt;br /&gt;
		testWindowCenter.topWidget:push(theFormattedText.bottomWidget)&lt;br /&gt;
&lt;br /&gt;
		return testWindowCenter&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;What it does&amp;#039;&amp;#039;: Add a small text field to the top left corner of the page (can be tweaked into centered/right/left/bottom)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Warning&amp;#039;&amp;#039;: At the moment you can launch it in editor only through the console panel. But it works eventualy when exporting&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardA-L|LeonardA-L]] ([[User talk:LeonardA-L|talk]]) 16:51, 24 April 2015 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Forcing a character change ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function setCharacterToThief()&lt;br /&gt;
	local cm=common.CommonUtils.getCharacterSelectionManager()&lt;br /&gt;
	local cha=trinebase.gameplay.TrineCharacterThief&lt;br /&gt;
	cm:forceCharacterChange(0,cha)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;What it does&amp;#039;&amp;#039;: Sets the character to thief&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Parameters&amp;#039;&amp;#039;: None&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Editor version&amp;#039;&amp;#039;: &amp;#039;&amp;#039;&amp;#039;v3&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardA-L|LeonardA-L]] ([[User talk:LeonardA-L|talk]]) 14:52, 25 April 2015 (UTC)&lt;/div&gt;</summary>
		<author><name>AnteroFB</name></author>
	</entry>
</feed>