Jump to content

Calling back a function is not working


Recommended Posts

Hello everybody, today I made a countdown script and I tried to add an export function, but it's not working for some reason. I think I've done everything well, but here's my code:

meta:

    

client:

local sx, sy = guiGetScreenSize () 
function startCountDown ( source ) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage ( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/3.png",false) 
    setTimer ( Countdown2, 1300, 1 ) 
    local sound = playSound("tick.mp3", false) 
end 
function Countdown2 ( source ) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/2.png",false) 
    setTimer ( Countdown1, 1300, 1 ) 
    local sound = playSound("tick.mp3", false) 
end 
function Countdown1 ( source ) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/1.png",false) 
    setTimer ( Countdown0, 1300, 1 ) 
    local sound = playSound("tick.mp3", false) 
end 
function Countdown0 ( source ) 
    guiSetVisible ( imagecount, false ) 
    imagecount = guiCreateStaticImage( (670 / 1600) * sx, (140 / 1300) * sy, (250 / 1600) * sx, (220 / 1300) * sy,"images/go.png",false) 
    setTimer ( CountdownEnd, 3000, 1 ) 
    local sound = playSound("go.mp3", false) 
end 
function CountdownEnd ( source ) 
    guiSetVisible ( imagecount, false ) 
end 
addCommandHandler ( "cd", startCountDown ) 
addEvent("startCountDown", true) 
addEventHandler("startCountDown", startCountDown) 

server:

function startCountDown(player) 
    if isElement(player) then 
        triggerClientEvent(player, "startCountDown", getRootElement()) 
    end 
end 

the way I tried to call it in server side script:

exports.countdown:startCountDown(source) 

What's the problem with my codes?

Link to comment

Well, I know if you don't define the type ( client, server ) at the script, it's gonna be server by default, but I don't know if it works like that with an export function. Try to put type="server" and see if it works. Also, I'd put an 'else' statement after the 'isElement' just to make things easier and see if the passed argument is an element or not.

Link to comment

Debug your code using outputDebugString.

Put one in server side startCountDown outside the if statement and one inside, and then put another one in client side startCountDown.

My guess is that 'source' that you call the function with is not an element.

Link to comment

make the type as "server" on first one, try after that

<meta> 
    <script src="countdownC.lua" type="client" /> 
    <script src="countdownS.lua" type="server" /> 
    <file src="images/1.png" /> 
    <file src="images/2.png" /> 
    <file src="images/3.png" /> 
    <file src="images/go.png" /> 
    <file src="go.mp3" /> 
    <file src="tick.mp3" /> 
    
    <export function="startCountDown" type="server" /> 
    <export function="startCountDown" type="client" /> 
</meta> 

what is the clientside for anyway?

Link to comment
make the type as "server" on first one, try after that
<meta> 
    <script src="countdownC.lua" type="client" /> 
    <script src="countdownS.lua" type="server" /> 
    <file src="images/1.png" /> 
    <file src="images/2.png" /> 
    <file src="images/3.png" /> 
    <file src="images/go.png" /> 
    <file src="go.mp3" /> 
    <file src="tick.mp3" /> 
    
    <export function="startCountDown" type="server" /> 
    <export function="startCountDown" type="client" /> 
</meta> 

what is the clientside for anyway?

I've already wrote it there. But it's working on client side, tested it with a command, but in server side it's not working.

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