Jump to content

Call/Exports function


ViRuZGamiing

Recommended Posts

Hi guys

 

I was looking into:

call

and I was wondering, for example; you have the function

outputChatBox("")

which works both client and server side with the same name. Will I be able to do the same with exports. Example;

Client

function drawDxStuff ()
  --dx stuff
end

addEvent("drawDxStuff", true)
addEventHandler("drawDxStuff", getRootElement(), drawDxStuff)

Server

function drawDxStuff()
  triggerClientEvent(source, "drawDxStuff", source) --source would probably be the player calling the function
end

Meta

<export function="drawDxStuff" type="server"/>
<export function="drawDxStuff" type="client"/>

 

Would this work or will this give an error cause they have the same name or for other reasons?

Kind Regards

Link to comment
46 minutes ago, Walid said:

function drawDxStuff(player)
    if player and isElement(player) then
        triggerClientEvent(player, "drawDxStuff", player)
    end 
end

Then use this server side


exports.resourceName:drawDxStuff(player)

And in the dx stuff part just added (onClientRender) event

I do know how that works, mine is just an analogue example to show you what I mean, I do know i'd need an onClientRender, etc. it could've been GUI as well, just an example.

 

My question is all about a client OR server sided function which can be called from both client AND server side with the same name 'exported'.

For example (as mentioned before): outputChatBox() which is both Server and Client sided (Shared Function)

Link to comment
2 hours ago, ViRuZGamiing said:

Would this work or will this give an error cause they have the same name or for other reasons?

Yeah, you can export both functions with the same name as long as the functions are present on both the server and client. I did the same thing on one of my scripts before. Nothing wrong with your example.

Edited by Tails
  • 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...