Jump to content

Problem with an exported function


Adde

Recommended Posts

Hello, I wounder if anyone know what the message in debug means/want to tell me. I don´t understand what I am doing wrong.

I am using a topchat script and want to trigger that from another script.

I am supposed to trigger this in another script:

outputTopChat("Respawning ALL empty vehicles In 25 Seconds", 255, 255, 255)

How I added it in another script:

exports["topchat"]:outputTopChat("Respawning ALL empty vehicles In 25 Seconds", 255, 255, 255)

What it tells me in debug:

ERROR: call:failed to call"topchat:outputTopChat"[string"?"]

Link to comment
  • Discord Moderators

In case you haven't, you might want to read about "call" on the wiki.

Your syntax is correct, but you need to make sure that "outputTopChat" is exported in the resource meta.xml

The error basically means that it can't find the exported function.

Link to comment

To make this easier, you can add this to the top;

local topchat = exports.topchat; 

After that, you can just call a function out of there like this:

topchat:outputTopChat("respawning all empty vehicles in 25 seconds", 255, 255, 255); 

This gives you the advantage to rename your project / resource and you just have to replace line 1, instead of line 1, 5, 10, 31, etc. :) But make sure that your resource name doesn't contain any slashes, stripes or what ever. If it does, you've to change the first line to;

local topchat = exports["Top-chat"]; 

Link to comment
Oh, I read on wiki but I missed that I had to export the function from meta. So I should add this right?:

If you're creating the function client-side, then yes, you should use that. If you're making it server-side, then you should switch to "server" instead, or in case both, then "shared".

Link to comment
Oh, I read on wiki but I missed that I had to export the function from meta. So I should add this right?:

If you're creating the function client-side, then yes, you should use that. If you're making it server-side, then you should switch to "server" instead, or in case both, then "shared".

Okay :) yes ofc i know that i should switch depended on client/server.

It still don´t work... :/

Link to comment

Meta:

    type="script" description="Topchat" version="1.0" /> 
    

Server:

function respawn() 
local accountname = getAccountName (getPlayerAccount(source)) 
if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "HeadAdmin" ) ) then 
exports["topchat"]:outputTopChat("Respawning ALL empty vehicles In 25 Seconds", 255, 255, 255) 
setTimer(function () 
local vehicles = getElementsByType ( "vehicle" )  
for k, vehicle in ipairs ( vehicles ) do 
if checkEmpty( vehicle ) then 
local seats = getVehicleMaxPassengers(vehicle) 
resetVehicleIdleTime ( vehicle )  
respawnVehicle ( vehicle ) 
end 
end 
end, 25000, 1) 
end  
end 
addEvent( "respawn", true ) 
addEventHandler( "respawn", getRootElement(), respawn ) 

Link to comment
  • Moderators

No just remove that line from your meta.xml:

<export function="outputTopChat" type="client"/> 

This line must only be in the meta of the resource that provides that function.

The second thing you must do is to start the resource that contains that fonction in order to be called.

Link to comment
No just remove that line from your meta.xml:
<export function="outputTopChat" type="client"/> 

This line must only be in the meta of the resource that provides that function.

The second thing you must do is to start the resource that contains that fonction in order to be called.

I am using meta in topchat resource and server.lua in another resource, both are running.

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