Jump to content

Triggers Issues


Overkillz

Recommended Posts

Hello dear community. Yesterday I've got an problem with the triggers that I really dont know why it is not working properly.

When I try to do a trigger to the event: ontestRegisterE It doesn't execute the function: whateverFunctionName

-- ##EVENTS PART
function addingEvent()
    addEvent( "ontestRegisterE", true )
end
addingEvent()

function addingEventHandler()
    addEventHandler( "ontestRegisterE",getRootElement(), whateverFunctionName )
end

-- ## FUNCTION PART
function whateverFunctionName()
    outputChatBox("The Trigger Should work")
end

--## TRIGGER RECEIVED
function triggerFromServer()
	outputDebugString("Trigger Received")
    addingEventHandler()
end
addEvent("onGetTriggerFromServer", true)
addEventHandler("onGetTriggerFromServer", root, triggerFromServer)

 

onGetTriggerFromServer is working correctly. I get the outputDebugString Message and it should start addingEventHandler() but when I try to do a trigger to ontestRegisterE it doesn't work.

I don't want to do the following method 

function whateverFunctionName()
    outputChatBox("The Trigger Should work")
end
addEvent( "ontestRegisterE", true )
addEventHandler( "ontestRegisterE",getRootElement(), whateverFunctionName )

I hope you can help me, thanks.

Regards.

Link to comment
  • Moderators

Hmm, is your timing correct? (When is the second event being called)

Is the eventName correct? Your test events are not correctly camelcase named, which might be correct named on serverside. ontest > onTest

And how do you trigger?

 

  • Like 1
Link to comment
2 hours ago, IIYAMA said:

Hmm, is your timing correct? (When is the second event being called)

Is the eventName correct? Your test events are not correctly camelcase named, which might be correct named on serverside. ontest > onTest

And how do you trigger?

 

Yes it is. This is how I run everything

--## Lobby.lua
function joinArena(arenaNo)
	if tonumber(arenaNo) == 1 then
		triggerServerEvent ( "onPlayerJoinArena", localPlayer, 1 )
	end
end
bindKey("1","down",joinArena)

--## Server.lua
room[thisArena].joinArena = function (arenaNo) -- ## <-- room table and thisArena are defined
	if arenaNo ~= thisArena then
		return
	end
	triggerClientEvent(source, "onClientRoomJoin", source, thisArena)
end
addEvent("onServerRoomJoin",true)
addEventHandler("onServerRoomJoin",getRootElement(),room[thisArena].joinArena)

--## Client.lua
function addingEvent()
    addEvent( "ontestRegisterE", true )
end
addingEvent()

function addingEventHandler()
    addEventHandler( "ontestRegisterE",getRootElement(), whateverFunctionName )
end

function whateverFunctionName()
    outputChatBox("The Trigger Should work")
end

addEvent("onClientRoomJoin", true)
addEventHandler("onClientRoomJoin", root, function(arenaNo)
	if arenaNo ~= thisArena then
		return
	end
	addingEventHandler()
	outputChatBox("Succesfully joined at the room ")
end)

-- ##TRIGGER FROM THE OTHER RESOURCE
triggerClientEvent(source,"ontestRegisterE",source)

And I said before. If I use the following method instead the previous one, the code works

function whateverFunctionName()
    outputChatBox("The Trigger Should work")
end
addEvent( "ontestRegisterE", true )
addEventHandler( "ontestRegisterE",getRootElement(), whateverFunctionName )

I hope u can help me. Thanks.

Regards.

Link to comment
9 minutes ago, IIYAMA said:

As it is now, the code triggers immediately while loading the resource and source is not defined.

 

 

It is

function getMapSettings()
	triggerClientEvent(source,"ontestRegisterE",source)
end
addEvent("onRequestMapSettings",true)
addEventHandler("onRequestMapSettings",root,getMapSettings)

The script is triggered correctly when I use the following method but I won't use it due to I have other goals with it.

function whateverFunctionName()
    outputChatBox("The Trigger Should work")
end
addEvent( "ontestRegisterE", true )
addEventHandler( "ontestRegisterE",getRootElement(), whateverFunctionName )

 

Edited by Overkillz
Link to comment
  • Moderators
2 hours ago, Overkillz said:

Problem fixed. For a weird reason one of the scripts wan't restarting and the changes weren't being applied. 

Anyways thanks for ur help. It was a f**** mistake by me. Around a f**** day looking for the error but now it is solved.

Thanks and regards.

Sometimes by just adding a random debug line in your code, it can reveal not updated code.:smilebox:

Edited by IIYAMA
  • Like 1
Link to comment

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...