Here's what I have:
Code: Select all
defineObject{
name = "helper_functions",
class = "ScriptEntity",
helloWorld = function()
print("hello World!")
end,
}
Code: Select all
defineObject{
name = "helper_functions",
class = "ScriptEntity",
helloWorld = function()
print("hello World!")
end,
}
Code: Select all
cloneObject{
name = "HelloDoor",
baseObject = "dungeon_door_metal",
onOpen = function()
local helloScript = [[
function helloWorld()
print('Hello world')
end
]]
spawn("script_entity", 1,1,1,0,'helperFunctions')
helperFunctions:setSource(helloScript)
end
}
Code: Select all
spawn("HelloDoor", 1,1,1,0, 'door')
door:open()
door:destroy()
Code: Select all
helperFunctions:helloWorld()
Code: Select all
onMove = function(monster, dir)
local helper = findEntity("helper")
if (helper == null) then
spawn("script_entity", monster.level, monster.x, monster.y, 0, "helper")
local helper = findEntity("helper")
local helloScript = [[
function helloWorld()
print('hello world')
end
]]
helper:setSource(helloScript)
print('helper created.') --this works
else
print('helper exists.') --this works
helper:helloWorld() --this DIES
end
end,