<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Maratis forum - Code Snippets.]]></title>
	<link rel="self" href="http://forum.maratis3d.com/extern.php?action=feed&amp;tid=924&amp;type=atom"/>
	<updated>2014-04-30T16:09:27Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.maratis3d.com/viewtopic.php?id=924</id>
		<entry>
			<title type="html"><![CDATA[Re: Code Snippets.]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=6739#p6739"/>
			<content type="html"><![CDATA[<h5>Automatically type text</h5><p>: Thanks to Vegas for this one. I just modified it a bit to make it easier to understand. </p><div class="codebox"><pre><code>--time variable
t = 0

--initialize counter variable
count = 0


function TypeText(typedText,delay,usedText)
    setText(usedText, T1text)
    
    --increment timer
    t = t + 1
    
    -- Change 5 to a different value to increase or decrease typing speed. Lower is faster. 5 is the default.
    if t == delay then
        count = count + 1
        t = 0
    end
    
    -- it&#039;s that string.sub thing who&#039;s writing letter one by one
    for i=1, count do T1text = string.sub (typedText, 1, 0+i) end
    
    -- Stop counting when we are at the end of the line
    if count == string.len(typedText) then t = 0 end
end</code></pre></div><h5>Explanation</h5><div class="codebox"><pre><code>function TypeText(typedText,delay,usedText)</code></pre></div><p>The typedText parameter should be a variable with a string data type. The speed is actually the &quot;delay&quot;, so lower numbers are faster. The usedText parameter is the text object you want to use.</p>]]></content>
			<author>
				<name><![CDATA[Tutorial Doctor]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2493</uri>
			</author>
			<updated>2014-04-30T16:09:27Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=6739#p6739</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Code Snippets.]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=6738#p6738"/>
			<content type="html"><![CDATA[<h5>Toggle a Light on and off using a specified key</h5><div class="codebox"><pre><code>lightState = true

function ToggleLight(object,key)
    if lightState==false and onKeyDown(key)then
        setLightIntensity(object,1)
        lightState = true
        
    elseif lightState==true and onKeyDown(key)then
        setLightIntensity(object,0)
        lightState = false
    end
end</code></pre></div><p>They &quot;key&quot; parameter must be in double quotes and can use any of the KEY LITERALS here:<br /><a href="http://wiki.maratis3d.org/index.php?title=Lua_scripting">http://wiki.maratis3d.org/index.php?title=Lua_scripting</a></p>]]></content>
			<author>
				<name><![CDATA[Tutorial Doctor]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2493</uri>
			</author>
			<updated>2014-04-30T16:05:32Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=6738#p6738</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Code Snippets.]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=6737#p6737"/>
			<content type="html"><![CDATA[<h5>Click an object from the view of a Camera:</h5><div class="codebox"><pre><code>clicked = false

function Click(objectName,camera)
    --[[----------------------------------------------------------------------UNPROJECTED POINT]]
    mx = getAxis(&quot;MOUSE_X&quot;)
    my = getAxis(&quot;MOUSE_Y&quot;)    

    V1 = getUnProjectedPoint(camera, vec3(mx, my, 0))
    V2 = getUnProjectedPoint(camera, vec3(mx, my, 1))
    
    point = rayHit(V1,V2,objectName)  -- note that rayHit only detects objects with physics enabled
    
    if point then 
        Xname = getName(objectName)
        Xobj = getObject(Xname)
        --setText(text,Xname)
        --print(Xname)
        
        if Xname == getName(objectName) and onKeyDown(&quot;MOUSE_BUTTON1&quot;) then 
            deactivate(Xobj)            
            playSound(sound) 
            clicked = true 
        else 
            clicked = false 
        end
    end
end    </code></pre></div><p>The parameters it takes is the object you want to click, and the camera from which you want to click the object.</p>]]></content>
			<author>
				<name><![CDATA[Tutorial Doctor]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2493</uri>
			</author>
			<updated>2014-04-30T15:52:35Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=6737#p6737</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Code Snippets.]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=6287#p6287"/>
			<content type="html"><![CDATA[<p>I want to post a collection of code snippets that do useful things you could use in your game. I will try to keep the code short and easy to understand;</p><h5>Clone an object on another object&#039;s location:</h5><div class="codebox"><pre><code>function offsetClone(object1,offset,object2)
    if onKeyUp(&quot;M&quot;) then
        objectPosition = getPosition(object2)
        clonedObject = getClone(object1)
        setPosition(clonedObject,{objectPosition[1] ,objectPosition[2] + offset,objectPosition[3]})
    end
end</code></pre></div><h5>How it works:</h5><p>This function takes three arguments:<br />-The object whose location you want to use<br />-The direction along the Y axis you want to offset the clone<br />-The object you want to clone</p><h5>Usage:</h5><div class="codebox"><pre><code>function onSceneUpdate()
offsetClone(clone,3,object)
end</code></pre></div><p>It can be read:<br /></p><div class="codebox"><pre><code>Offset the clone object three units from another object (along the Y axis)</code></pre></div><h5>More functionality:</h5><div class="codebox"><pre><code>function offsetClone(object1,offset,object2,axis)
    if onKeyUp(&quot;M&quot;) then
        objectPosition = getPosition(object2)
        clonedObject = getClone(object1)
        
        x_axis = {objectPosition[1] + offset,objectPosition[2],objectPosition[3]}
        y_axis = {objectPosition[1] ,objectPosition[2] + offset,objectPosition[3]}
        z_axis = {objectPosition[1] ,objectPosition[2],objectPosition[3] + offset}

    
        setPosition(clonedObject,axis)
    end
end</code></pre></div><div class="codebox"><pre><code>offsetClone(clone,.5,object,x_axis)</code></pre></div><p>It can be read:<br /></p><div class="codebox"><pre><code>Offset the clone object .5 units from another object along the X axis</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Tutorial Doctor]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2493</uri>
			</author>
			<updated>2014-01-30T00:37:02Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=6287#p6287</id>
		</entry>
</feed>
