MCPcopy Create free account
hub / github.com/defold/defold / Script_Delete

Function Script_Delete

engine/gameobject/src/gameobject/gameobject_script.cpp:1912–1980  ·  view source on GitHub ↗

delete one or more game object instances * Delete one or more game objects identified by id. Deletion is asynchronous meaning that * the game object(s) are scheduled for deletion which will happen at the end of the current * frame. Note that game objects scheduled for deletion will be counted against * `max_instances` in "game.project" until they are actually removed. *

Source from the content-addressed store, hash-verified

1910 *
1911 */
1912 static int Script_Delete(lua_State* L)
1913 {
1914 int args = lua_gettop(L);
1915
1916 if(args > 2)
1917 {
1918 return luaL_error(L, "go.delete invoked with too many argumengs");
1919 }
1920
1921 // deduct recursive bool parameter (optional last parameter)
1922 bool recursive = false;
1923 if(args != 0)
1924 {
1925 if(lua_isboolean(L, 1))
1926 {
1927 // if argument #1 is boolean, no more arguments are accepted
1928 if(args > 1)
1929 {
1930 return luaL_error(L, "go.delete expected one argument when argument #1 is boolean type");
1931 }
1932 recursive = lua_toboolean(L, 1);
1933 lua_pop(L, 1);
1934 --args;
1935 }
1936 else if(args > 1)
1937 {
1938 // if argument #1 isn't a boolean, it's resolved later. Argument #2 is required to be a boolean
1939 if(lua_isboolean(L, 2))
1940 {
1941 recursive = lua_toboolean(L, 2);
1942 }
1943 else
1944 {
1945 return luaL_error(L, "go.delete expected boolean as argument #2");
1946 }
1947 lua_pop(L, 1);
1948 --args;
1949 }
1950 }
1951
1952 // handle optional parameter #1 is table or nil
1953 if(args != 0)
1954 {
1955 if(lua_istable(L, 1))
1956 {
1957 int result = DeleteGOTable(L, recursive);
1958 if(result == 0)
1959 {
1960 assert(args == lua_gettop(L));
1961 }
1962 return result;
1963 }
1964 else if(lua_isnil(L, 1))
1965 {
1966 return luaL_error(L, "go.delete() invoked with first argument 'id' set to 'nil'");
1967 }
1968 }
1969

Callers

nothing calls this directly

Calls 10

lua_gettopFunction · 0.85
luaL_errorFunction · 0.85
lua_tobooleanFunction · 0.85
DeleteGOTableFunction · 0.85
ResolveInstanceFunction · 0.85
IsBoneFunction · 0.85
dmHashReverseSafe64AllocFunction · 0.85
GetIdentifierFunction · 0.85
DeleteFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected