check if the specified game object exists * This function can check for game objects in any collection by specifying * the collection name in the URL. * * @name go.exists * @param url [type:string|hash|url] url of the game object to check * @return exists [type:boolean] true if the game object exists * * @examples * Check if game object "my_game_object
| 2083 | * ``` |
| 2084 | */ |
| 2085 | int Script_Exists(lua_State* L) |
| 2086 | { |
| 2087 | DM_LUA_STACK_CHECK(L, 1); |
| 2088 | if (lua_isnil(L, 1)) |
| 2089 | { |
| 2090 | return luaL_error(L, "The url shouldn't be `nil`"); |
| 2091 | } |
| 2092 | |
| 2093 | // get "this" instance |
| 2094 | ScriptInstance* i = ScriptInstance_Check(L); |
| 2095 | Instance* instance = i->m_Instance; |
| 2096 | |
| 2097 | // resolve target URL |
| 2098 | dmMessage::URL receiver; |
| 2099 | dmScript::ResolveURL(L, 1, &receiver, 0x0); |
| 2100 | |
| 2101 | dmMessage::URL sender; |
| 2102 | dmScript::GetURL(L, &sender); |
| 2103 | dmMessage::URL target; |
| 2104 | dmScript::ResolveURL(L, 1, &target, &sender); |
| 2105 | |
| 2106 | dmGameObject::HInstance target_instance = 0; |
| 2107 | |
| 2108 | // Check if target is in the same collection |
| 2109 | if (receiver.m_Socket == dmGameObject::GetMessageSocket(instance->m_Collection->m_HCollection)) |
| 2110 | { |
| 2111 | // Same collection - use current collection |
| 2112 | target_instance = dmGameObject::GetInstanceFromIdentifier(dmGameObject::GetCollection(instance), target.m_Path); |
| 2113 | } |
| 2114 | else |
| 2115 | { |
| 2116 | // Different collection - find target collection by socket |
| 2117 | dmhash_t target_socket_hash = dmMessage::GetSocketNameHash(receiver.m_Socket); |
| 2118 | if (target_socket_hash != 0) |
| 2119 | { |
| 2120 | dmGameObject::HRegister regist = dmGameObject::GetRegister(instance->m_Collection->m_HCollection); |
| 2121 | dmGameObject::HCollection target_collection = dmGameObject::GetCollectionByHash(regist, target_socket_hash); |
| 2122 | if (target_collection != 0) |
| 2123 | { |
| 2124 | target_instance = dmGameObject::GetInstanceFromIdentifier(target_collection, target.m_Path); |
| 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | lua_pushboolean(L, target_instance != 0); |
| 2130 | return 1; |
| 2131 | } |
| 2132 | |
| 2133 | |
| 2134 | /*# convert position to game object's coordinate space |
nothing calls this directly
no test coverage detected