<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - Pass data between levels]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=642</link>
		<description><![CDATA[The most recent posts in Pass data between levels.]]></description>
		<lastBuildDate>Fri, 12 Apr 2013 23:40:06 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Pass data between levels]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=3985#p3985</link>
			<description><![CDATA[<p>Hi,<br />Yes, a way to pass values from Lua to specific levels would be nice <img src="http://forum.maratis3d.com/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />I realized I was in need of something similar today and hacked together two api functions so I could &quot;preserve&quot; Lua numbers from one level to another.</p><p>To use a game plugin is much better, but I&#039;m not there yet.<br />I just drop the code here anyway in case it&#039;s useful for someone else.</p><div class="codebox"><pre><code>file: ...Maratis/Common/MScript/MScript.cpp

#define NUMSLOTS 64
static double g_persistentSlots[NUMSLOTS];

//...

static int getPersistentSlot(lua_State * L)
{
    if(! isFunctionOk(L, &quot;getPersistentSlot&quot;, 1))
        return 0;

    int i = luaL_checkinteger(L, -1);
    if(i&lt;0 || i&gt;NUMSLOTS)
    {
        printf(&quot;ERROR get persistent slot: %d, invalid index!\n&quot;, i);
        return 0;
    }

    lua_pushnumber(L, g_persistentSlots[i-1]);
    return 1;
}

static int setPersistentSlot(lua_State * L)
{
    if(! isFunctionOk(L, &quot;setPersistentSlot&quot;, 2))
        return 0;

    int i = luaL_checkinteger(L, -2);
    if(i&lt;1 || i&gt;NUMSLOTS)
    {
        printf(&quot;ERROR set persistent slot: %d, invalid index!\n&quot;, i);
        return 0;
    }

    g_persistentSlots[i-1] = luaL_checknumber(L, -1);
    return 0;
}

// ...
// Then register these functions in MScript::init with the other API functions.
// ...</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (esodax)]]></author>
			<pubDate>Fri, 12 Apr 2013 23:40:06 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=3985#p3985</guid>
		</item>
		<item>
			<title><![CDATA[Re: Pass data between levels]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=3970#p3970</link>
			<description><![CDATA[<p>There is no ready made feature right now, we&#039;ll try to do something in the future.</p><p>Right now you can :<br />- write and read a file in lua<br />- use a custom game plugin to handle it (best)</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Thu, 11 Apr 2013 04:34:19 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=3970#p3970</guid>
		</item>
		<item>
			<title><![CDATA[Pass data between levels]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=3959#p3959</link>
			<description><![CDATA[<p>Is there a way to pass data between levels in lua?<br />A sort of global variables for lua?</p>]]></description>
			<author><![CDATA[dummy@example.com (SadWolf)]]></author>
			<pubDate>Wed, 10 Apr 2013 19:24:20 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=3959#p3959</guid>
		</item>
	</channel>
</rss>
