Jump to content

Call/Exports function


ViRuZGamiing

Recommended Posts

Posted

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

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted (edited)

can't seem to be able to edit my post on the "new" forum design 50% of the time appearantly

Edited by ViRuZGamiing

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted

Maybe add client and server to the names since you are trying to call one export while there are 2 results for this. :P

Nothing is impossible when you acquire the knowledge
 
Posted
17 minutes ago, Syntrax# said:

Maybe add client and server to the names since you are trying to call one export while there are 2 results for this. :P

So I do have to name them by 2 different names, it's not possible to have 1 name?

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted
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

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
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)

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

Posted (edited)
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

Discord: its.tails

Posted
1 hour ago, Tails said:

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.

Thanks for the clear answer!

  • Like 1

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

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