• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Reading text from a writeable/readable item in lua

Depends on version.

Maybe:
getItemText(item.uid)
or
getItemAttribute(item.uid, "text")
 
I just looked at source and there seems to be no function like this.

So add this function:
[cpp]int32_t LuaScriptInterface::luaGetItemText(lua_State* L)
{
//getItemText(uid)
uint32_t uid = popNumber(L);

ScriptEnvironment* env = getScriptEnv();

const Item* item = env->getItemByUID(uid);
if(item)
lua_pushstring(L, item->getText().c_str());
else
{
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}[/cpp]

Also, dont forget to register the function in luascript.cpp and declare it in luascript.h.
 
I just looked at source and there seems to be no function like this.

So add this function:
[cpp]int32_t LuaScriptInterface::luaGetItemText(lua_State* L)
{
//getItemText(uid)
uint32_t uid = popNumber(L);

ScriptEnvironment* env = getScriptEnv();

const Item* item = env->getItemByUID(uid);
if(item)
lua_pushstring(L, item->getText().c_str());
else
{
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}[/cpp]

Also, dont forget to register the function in luascript.cpp and declare it in luascript.h.

As far as i know, functions like 'getItemText', 'getItemName', 'getItemDescription', etc.. are added in libs.
Personally, i prefer to use 'getItemAttribute(uid, "attr")'
 
As far as i know, functions like 'getItemText', 'getItemName', 'getItemDescription', etc.. are added in libs.
Personally, i prefer to use 'getItemAttribute(uid, "attr")'

I did not find any matching function in global.lua nor in sources, also there is no getItemAttribute either.
Correct me if I am wrong.
 
Back
Top