Jump to content

True, False or 0, 1, -1?


Go to solution Solved by Mali,

Recommended Posts

  • Active Member

Hey guys,

I'm wondering what should I use in this function, because everywhere in LUA .cpp functions are 0 or 1 or -1, can someone explain me what does it mean and should I use number or boolean return in LUA .cpp functions?

Spoiler
ALUA(game_open_safebox)
	{
		CQuestManager& q = CQuestManager::instance();
		LPCHARACTER ch = q.GetCurrentCharacterPtr();

		if (ch->GetExchange())
		{
			ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("´Ů¸Ą°Ĺ·ˇĂ˘ŔĚ ż­¸°»óĹÂżˇĽ­´Â â°í¸¦ ż­Ľö°ˇ ľř˝Ŕ´Ď´Ů."));
			/// return false; or return 0, 1, -1;???
		}
		else
		{
			ch->SetSafeboxOpenPosition();
			ch->ChatPacket(CHAT_TYPE_COMMAND, "ShowMeSafeboxPassword");
		}

		return 0;
	}

 

Thanks for possible answers!

Sincerely,

ReFresh

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Developer

Honestly, I've never used return -1. However, if you give 0 or 1 to the return command, it will directly interpret it as a boolean

return 0; /*or*/ return false; //they are equal
return 1; /*or*/ return true; //they are equal

btw, the result of return has type int

  • Metin2 Dev 1

503953077003354113.png

Link to comment
Share on other sites

  • Honorable Member
  • Solution

return value: number of results (https://www.lua.org/pil/26.1.html)

static int l_sin (lua_State *L) {
      double d = luaL_checknumber(L, 1);
      lua_pushnumber(L, sin(d));
      return 1;  /* number of results */
    }

Example from m2:

Spoiler
	int forked_sungzi_start_pos( lua_State* L )
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

		const ForkedSungziMapInfo& info = CThreeWayWar::instance().GetEventSungZiMapInfo();

		lua_pushnumber( L, info.m_iForkedSungziStartPosition[ch->GetEmpire()-1][0] );
		lua_pushnumber( L, info.m_iForkedSungziStartPosition[ch->GetEmpire()-1][1] );

		return 2; // 2 result
	}

	int game_get_event_flag(lua_State* L)
	{
		CQuestManager& q = CQuestManager::instance();

		if (lua_isstring(L,1))
			lua_pushnumber(L, q.GetEventFlag(lua_tostring(L,1)));
		else
			lua_pushnumber(L, 0);

		return 1; // 1 result
	}
  
  	int game_open_safebox(lua_State* /*L*/)
	{
		CQuestManager& q = CQuestManager::instance();
		LPCHARACTER ch = q.GetCurrentCharacterPtr();
		ch->SetSafeboxOpenPosition();
		ch->ChatPacket(CHAT_TYPE_COMMAND, "ShowMeSafeboxPassword");
		return 0; // no result
	}
  	
  

 

Other examples:

Spoiler
static int c_swap (lua_State *L) {
    //check and fetch the arguments
    double arg1 = luaL_checknumber (L, 1);
    double arg2 = luaL_checknumber (L, 2);

    //push the results
    lua_pushnumber(L, arg2);
    lua_pushnumber(L, arg1);
  
    return 2; // number of results
}

 

 

  • Metin2 Dev 1
  • Good 1

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Similar Content

  • Activity

    1. 3

      Crystal Metinstone

    2. 3

      Feeding game source to LLM

    3. 113

      Ulthar SF V2 (TMP4 Base)

    4. 3

      Feeding game source to LLM

    5. 0

      Target Information System

    6. 3

      Feeding game source to LLM

    7. 2

      anti exp explanation pls

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.