Jump to content

Custom event is not working


Recommended Posts

Posted

Hello!

I am trying to make a new custom server-sided event for my weather system, but for some reason it doesn't work in an other script. Here's the handling of my custom event in weatherS.lua:

addEvent("onWeatherChange", true)
local lastWeather = getWeather()
function checkNewWeather()
    local weather = getWeather()
    if weather ~= lastWeather then
        triggerEvent("onWeatherChange", getRootElement(), lastWeather, weather)
        lastWeather = weather
    end
end
setTimer(checkNewWeather, 50, 0)

And here's the part that doesn't work inside waterS.lua:

function testWeatherEvent(lastWeather, weather)
  	outputChatBox(tostring(weather))
	outputChatBox("lol")
end
addEventHandler("onWeatherChange", getRootElement(), testWeatherEvent)

It doesn't output anything from the waterS.lua, not even the "lol" string.

Finally, here's my meta.xml:

<meta>
	<download_priority_group/>2<download_priority_group/>
	
	<script src="waterS.lua" type="server" />
	<script src="weatherS.lua" type="server" />
	<script src="timecycS.lua" type="server" />
	
	<export function="onWeatherChange" type="server" />
</meta>

Could somebody tell me what is the problem or what am I doing wrong, or help me fixing this?

Your signature image is too large.

Removed

Posted

Try removing

<export function="onWeatherChange" type="server" />

from your meta. It's not a function.

6C73yFv.png

Did I help you?

Mmpe7Jm.gif


NeXuS™#0001

Posted

This one works totally fine for me:

 

Spoiler

bdd93655657941b4af3be1d8636d0f72.png

0ab097d1ad8f42648ca0e980b339eab6.png

f78944dbe54f4f21b4a00822d5bd4283.png

1aa5c1aeee8946f29e929380ea5d298f.png

 

Just tested your script, works perfectly for me.
fcae97b587954a43b9f42b52fe2ed3f1.png

  • Like 1

6C73yFv.png

Did I help you?

Mmpe7Jm.gif


NeXuS™#0001

Posted

Fixed it by myself omg...

The problem was in the meta, I should write the weatherS.lua before the waterS.lua, not after the waterS.lua. Thank you anyway!

Your signature image is too large.

Removed

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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