<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Maratis forum - Adding 1 to any variable.]]></title>
	<link rel="self" href="http://forum.maratis3d.com/extern.php?action=feed&amp;tid=543&amp;type=atom"/>
	<updated>2013-01-13T12:28:11Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.maratis3d.com/viewtopic.php?id=543</id>
		<entry>
			<title type="html"><![CDATA[Adding 1 to any variable.]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=3368#p3368"/>
			<content type="html"><![CDATA[<p>Hey! I thought this was a useful tutorial so I&#039;m gonna put it up.</p><p>If you want to add, lets say 1 bullet to a variable then first you need to set up a variable for the bullet before the function onSceneUpdate().</p><p>So first you write:</p><p>bullet = 0 (remember that the variable &quot;Bullet&quot; is not the same as &quot;bullet&quot;)</p><p>and then the next part is to add increment. You do it like this.</p><p>Write a function for it before the onSceneUpdate():</p><p>function increment(i)</p><p>&nbsp; &nbsp; &nbsp; &nbsp;return i + 1</p><p>end</p><p>Then, inside onSceneUpdate function you write:</p><p>if onKeyDown(&quot;R&quot;) then</p><p>bullet = increment(bullet)</p><p>end</p><p>That will increase the bullets value by one. And if you want to see it happen in-game then just add a text to maratis from a true-type file (.ttf) and write Text0 = getObject(&quot;Text0&quot;) in the first row. And then inside onSceneUpdate function write:</p><p>setText(Text0, &quot;Bullet: &quot; .. bullet)</p><p>This will first set the text Text0 to the string (letters) &quot;Ammo: &quot; and then after that it will put the variable bullet. The two dots is for separating the string &quot;Ammo: &quot; and the variable bullet. So any time you want to separate any kind of texts or variables you have made just make two dots inbetween.</p><p>Next off if you want to decrease bullet, just add a decrement function before the onSceneUpdate function:</p><p>function decrement(i)</p><p>&nbsp; &nbsp; &nbsp; return i - 1</p><p>end</p><p>and write following code inside onSceneUpdate() function:</p><p>if onKeyDown(&quot;MOUSE_BUTTON1&quot;) then </p><p>&nbsp; &nbsp; &nbsp;bullet = decrement(bullet)</p><p>end</p><p>this will decrease the bullets value with 1. </p><p>This is the full code written together:</p><br /><p>Text0 = getObject(&quot;Text0&quot;)<br />bullet = 0</p><p>function increment(i)</p><p>&nbsp; &nbsp; &nbsp; return i + 1</p><p>end</p><p>function decrement(i)</p><p>&nbsp; &nbsp; &nbsp; return i - 1</p><p>end</p><p>function onSceneUpdate()</p><p>&nbsp; &nbsp; &nbsp; if onKeyDown(&quot;R&quot;) then</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bullet = increment(bullet)</p><p>&nbsp; &nbsp; &nbsp; end</p><p>&nbsp; &nbsp; &nbsp; if onKeyDown(&quot;MOUSE_BUTTON1&quot;) then </p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bullet = decrement(bullet)</p><p>&nbsp; &nbsp; &nbsp; end</p><p>end</p><br /><br /><p>Play around with it! See what you can do! <img src="http://forum.maratis3d.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><br /><br /><br /><br /><p>(Say what you think about the tutorial so I can fix any errors or any lack of clarity you might see)</p>]]></content>
			<author>
				<name><![CDATA[Pär]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1252</uri>
			</author>
			<updated>2013-01-13T12:28:11Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=3368#p3368</id>
		</entry>
</feed>
