minetest.global_exists

From Minetest Developer Wiki
Jump to: navigation, search

Contents

Syntax

minetest.global_exists(name)

Description

Checks if a global variable named name has been set, without triggering a warning.

(Note: Added after 0.4.12)

Parameters

  • name - The name of the global variable. This is a string, not a reference to the variable itself. For example, to test for the existence of a variable my_global, use minetest.global_exists("my_global") (noting the use of quotes).

Examples

-- API namespace for mod "mymod"
if not minetest.global_exists("mymod") then
   mymod = {}
end
 
function mymod.my_func(...)
   ...
end

Slightly more complicated because of short-circuit logic, but a bit more concise:

-- API namespace for mod "mymod"
mymod = (minetest.global_exists("mymod") and mymod) or {};
 
function mymod.my_func(...)
   ...
end
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox