Jump to content

help with exports


xTravax

Recommended Posts

hey im trying to call another script from another resource so that i can spawn a player when i want without using original resource to spawn it

-- client

exports.cspawn:otherTestFunction(localPlayer) 

-- meta

function="otherTestFunction" type="client" /> 

debugscript 3:

call: failed to call: cspawn:otherTestFunction

please help idk what im doing wrong

Link to comment

The reason is usually that you have an error in the exported function, otherwise you get other types of error outputs in the script debugger, try comment everything in "otherTestFunction" and add something simple like outputChatBox("test") just to see if that works and you get the output, if it does then you have a problem in your exported function which you can find by calling it from the same resource while debugging.

Link to comment

Ok so you got this error now: "attempt to call a nil value", that's a clear indicator that something doesn't exist, are you really sure that you have this line:

meta.xml

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

in the same resource you have the exported function? Are you completely sure that both these resources are running? Try to refresh all and then reconnect to make sure you get all the files you need.

Link to comment
  • Moderators

Ever heard of debugging? :|

/debugscript 3

local resource = getResourceFromName ( "cspawn" ) 
if resource then 
    local state = getResourceState (resource) 
    if state == "running" then 
        call (resource, "otherTestFunction", localPlayer ) 
    else 
        outputDebugString("Resource isn't running but: " .. state) 
    end 
else 
    outputDebugString("resource doesn't exist, ") 
end 

Edited by Guest
Link to comment
Ok so you got this error now: "attempt to call a nil value", that's a clear indicator that something doesn't exist, are you really sure that you have this line:

meta.xml

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

in the same resource you have the exported function? Are you completely sure that both these resources are running? Try to refresh all and then reconnect to make sure you get all the files you need.

its exactly that line,both resources are running and always gives that error

IIYAMA,

i really dont know how could you miss my DEBUGSCRIPT 3 LINE on my FIRST POST in this topic

obviously i know how to use it.

why to script if scripting basics aren't learned?

anyway i dont need a script to check if a resource is running because simply i have already checked that long time ago

and this thing still does not work..

Link to comment
Ok so you got this error now: "attempt to call a nil value", that's a clear indicator that something doesn't exist, are you really sure that you have this line:

meta.xml

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

in the same resource you have the exported function? Are you completely sure that both these resources are running? Try to refresh all and then reconnect to make sure you get all the files you need.

its exactly that line,both resources are running and always gives that error

IIYAMA,

i really dont know how could you miss my DEBUGSCRIPT 3 LINE on my FIRST POST in this topic

obviously i know how to use it.

why to script if scripting basics aren't learned?

anyway i dont need a script to check if a resource is running because simply i have already checked that long time ago

and this thing still does not work..

Are you sure that your code isn't mixed with any server-side functions? and you definite your script in meta as a client-side?

And you're using the function in a client-side script?

and at last, try this tutorial :

https://forum.multitheftauto.com/viewtopic.php?f=148&t=46167

Link to comment
  • Moderators

Because I am not reading every word of the forum? Not sure what kind of super human you are.

If you don't want to check if a script is running, then you get warnings and when you get warnings you get a little bit lagg.

and not only that little bit lagg, your server logs will be filled with it and your server will be starting slower while accessing the logs. But I won't say anything more about that, it's your own responsibility. bla bla bla.....

Post the function you are trying to access. (and what kind of file it is in)

Link to comment

@king not sure how can any serverside script mess up my client side as theres not a single part of code which would do that

and im calling client function from other script with this client file script

iyyama(usually people read first post at topics afaik)

[cspawn]\cspawn\script.lua

thats an example where a script would be in

cspawn is resource name

and this is the other client function which im triggering with exports

if getElementDimension(localPlayer) == 3 then 
button = guiCreateButton( 0.45, 0.5, 0.1, 0.1, "Spawn!", true ) 
fadeCamera ( false ) 
showCursor ( true ) 
else outputChatBox("bspawn_c: wrong dimension ") return end 
  
function otherTestFunction ( ) 
if getElementDimension(localPlayer) == 3 then 
outputChatBox("a") 
outputDebugString("aa") 
 else outputChatBox("bspawn_c10:  wrong dimension ") return end 
    --triggerServerEvent ( "spawnButtonForPlayer",localPlayer ) 
    --showCursor ( false ) 
    --guiSetVisible(button,false) 
end 
addEventHandler ( "onClientGUIClick", button, otherTestFunction, false ) 

Link to comment
  • Moderators

He means that you can't calling from serverside a client function. Which you aren't doing afaik, but if you haven't checked that, check it.

Else.

What if you don't attach that event handler? I know it is probably not the problem, but to be honest I have never attached addEventHandlers to my export functions.

You also have to mind timing of the scripts.

If you start both scripts at the same time, there is always one faster loaded. Which will most of the time go wrong when you have included other resources in the meta.xml. (the first export will fail in this case)

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