Jump to content

call a function out from a event


Kleinbart

Recommended Posts

Hi guys

 

This is working:

local event_handler = {}
function event_handler:onEvent(event)
	if event.id == world.event.S_EVENT_CRASH then --or any other event
		trigger.action.outText('Hello World' ,10 ,1)
	end
end
world.addEventHandler(event_handler)

 

And this doesn't work:

function doNothing()
	trigger.action.outText('Hello World' ,10 ,1)
end

local event_handler = {}
function event_handler:onEvent(event)
	if event.id == world.event.S_EVENT_CRASH then
		doNothing
	end
end
world.addEventHandler(event_handler)

 

Anyone knows why?

 

Thanks for your answer.

Link to comment
Share on other sites

here the exact script:

 

works:

local event_handler = {}
function event_handler:onEvent(event)
	if event.id == world.event.S_EVENT_CRASH then     -- or any other event
		trigger.action.outText('Hello World' ,10 ,1)
	end
end
world.addEventHandler(event_handler)

 

dosen't work:

function helloWorld()
	trigger.action.outText('Hello World' ,10 ,1)
end

local event_handler = {}
function event_handler:onEvent(event)
	if event.id == world.event.S_EVENT_CRASH then     -- or any other event
		helloWorld()
	end
end
world.addEventHandler(event_handler)

 

Link to comment
Share on other sites

Maybe your function needs to be global:

helloWorld = function()
	trigger.action.outText('Hello World' ,10 ,1)
end

local event_handler = {}
function event_handler:onEvent(event)
	if event.id == world.event.S_EVENT_CRASH then     -- or any other event
		helloWorld()
	end
end
world.addEventHandler(event_handler)

 

Link to comment
Share on other sites

I took the script that doesn't work, and just re-wrote few things the way I'd do and used MIST eventhandler, and it works :

 

function doNothing()
    trigger.action.outText('Hello World' ,10 ,true)
end
function crashtest(event)
    if event.id == world.event.S_EVENT_CRASH then
        doNothing()
    end
end
CrashID = mist.addEventHandler(crashtest)

 

That said I can't tell where and why your script is failing - crashtest on Khalifa tower .miz file attached.

3 hours ago, Kleinbart said:

I tested with global function. It still doesen't work.

 

test-crash-event.miz

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...