# Indicators of being ran in editor vs ran by bundled version

**URL:** <https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722>\
**Category:** Questions\
**Created:** [November 15, 2017, 7:52pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722 "2017-11-15T19:52:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [November 15, 2017, 7:52pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/1 "2017-11-15T19:52:37Z")

</div>

What would be the best way to detect if a build was ran through the editor (project-\>build) ?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [November 15, 2017, 8:23pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/2 "2017-11-15T20:23:48Z")

</div>

Hmm, good question. Not sure if this can be done. Well, maybe. Perhaps look at the current directory? Or maybe something from os.env()?

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [May 6, 2019, 12:53am UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/3 "2019-05-06T00:53:52Z")

</div>

Any idea on how to best do this? Now that I think about it again, maybe a way to do it would be to check if a file exists within the project directory which would not be specified to be included in the bundled version. That plus checking if it’s on a desktop OS first maybe so on platforms with an editor version it’s not checked.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [May 6, 2019, 3:39am UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/4 "2019-05-06T03:39:59Z")

</div>

Checking the existence of a file or checking the current directory should work reasonably well.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [May 6, 2019, 3:42am UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/5 "2019-05-06T03:42:58Z")

</div>

Here’s a simple method that seems to work. The context is needing a path to the bundle resources folder so that only one copy of files are needed in project directory.

```lua
local M = {}

--- Check if a file or directory exists in this path
function M.exists(file)
	local ok, err, code = os.rename(file, file)
	if not ok then
		if code == 13 then
			-- Permission denied, but it exists
			return true
		end
	end
	return ok, err
end

--- Check if a directory exists in this path
function M.isdir(path)
	-- "/" works on both Unix and Windows
	return M.exists(path.."/")
end

return M

```

```lua
local files = require("main.files")
local sys_info = sys.get_sys_info()

local function is_editor()
  if not (sys_info.system_name == "Windows" or sys_info.system_name == "Darwin" or sys_info.system_name == "Linux") then
    return false
  end

  if files.isdir("bundle_resources") then
    return true
  else
    return false
  end
end
...

  local extra_path = "."

  if is_editor() then
    extra_path = "./bundle_resources/common"
  end

```

---

<div class="post-metadata">

**Author:** ![SpencerWF](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/spencerwf/32/21158_2.png) [@SpencerWF](https://forum.defold.com/u/SpencerWF)\
**Post date:** [January 20, 2021, 12:12pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/6 "2021-01-20T12:12:10Z")

</div>

I’m looking to do this as well. Just checking if you are still using this solution?

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [January 20, 2021, 12:28pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/7 "2021-01-20T12:28:38Z")

</div>

What about this?

```
tostring(hash("test")) == "hash: [test]"

```

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 20, 2021, 1:14pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/8 "2021-01-20T13:14:40Z")

</div>

Note that this only determines if it’s a debug build or not. Not that it’s running from the editor.

---

<div class="post-metadata">

**Author:** ![SpencerWF](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/spencerwf/32/21158_2.png) [@SpencerWF](https://forum.defold.com/u/SpencerWF)\
**Post date:** [January 20, 2021, 1:19pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/9 "2021-01-20T13:19:45Z")

</div>

I’m not sure I understand this?

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 20, 2021, 1:29pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/10 "2021-01-20T13:29:11Z")

</div>

In debug mode, you can print out a hash value and see the original string (i.e. “hash: [test]” in this case).

Whereas in release mode, the debug strings are turned off.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 20, 2021, 2:50pm UTC](https://forum.defold.com/t/indicators-of-being-ran-in-editor-vs-ran-by-bundled-version/13722/11 "2021-01-20T14:50:13Z")

</div>

> [@SpencerWF](#):
>
> I’m looking to do this as well.

Another option might be to use sys.get\_application\_path(). When running from the editor, at least on macOS, you’ll get the path to the Defold.app.

```lua
local function is_editor()
	local path = sys.get_application_path()
	return path:match(".*%/Defold%.app") ~= nil -- macOS
		or path:match(".*%/Defold%.exe") ~= nil -- Windows
		or path:match(".*%/Defold") ~= nil -- Linux
end

```
