Kleinbart Posted April 4, 2021 Posted April 4, 2021 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.
Kleinbart Posted April 4, 2021 Author Posted April 4, 2021 i forgott the () only here. In the real script i have the (). But it doesent work.
Hardcard Posted April 5, 2021 Posted April 5, 2021 Paste the EXACT script you're using. [sIGPIC][/sIGPIC]
Kleinbart Posted April 5, 2021 Author Posted April 5, 2021 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)
dark_wood Posted April 5, 2021 Posted April 5, 2021 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)
Kleinbart Posted April 5, 2021 Author Posted April 5, 2021 I tested with global function. It still doesen't work.
toutenglisse Posted April 5, 2021 Posted April 5, 2021 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
Kleinbart Posted April 5, 2021 Author Posted April 5, 2021 So i will use MIST. Thanks a lot for helping.
Recommended Posts