<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Maratis forum - Pass data between levels]]></title>
	<link rel="self" href="http://forum.maratis3d.com/extern.php?action=feed&amp;tid=642&amp;type=atom"/>
	<updated>2013-04-12T23:40:06Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.maratis3d.com/viewtopic.php?id=642</id>
		<entry>
			<title type="html"><![CDATA[Re: Pass data between levels]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=3985#p3985"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[esodax]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1438</uri>
			</author>
			<updated>2013-04-12T23:40:06Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=3985#p3985</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Pass data between levels]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=3970#p3970"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2013-04-11T04:34:19Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=3970#p3970</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Pass data between levels]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=3959#p3959"/>
			<content type="html"><![CDATA[<p>Is there a way to pass data between levels in lua?<br />A sort of global variables for lua?</p>]]></content>
			<author>
				<name><![CDATA[SadWolf]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1268</uri>
			</author>
			<updated>2013-04-10T19:24:20Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=3959#p3959</id>
		</entry>
</feed>
