Jump to content

callRemote


'LinKin

Recommended Posts

Posted

Hello,

I've this code:

 addCommandHandler("getip", 
function() 
     local theIP = getServerIp() 
     outputChatBox(theIP) 
end) 
  
function getServerIp() 
    callRemote("http://www.nub.hj.cx/getServerIp.php", 
    function(value) 
        if (value ~= "ERROR") then 
        outputChatBox("Returning value...") 
            return value 
        end 
    end) 
    outputChatBox("Returning False...") 
    return false 
end 
  

And the problem is:

Error: attempt to concatenate local 'theIP' (a boolean value) Ln: 4

That's beacause when I call the function getServerIp() the result is NOT immediate, so, it will return false at first, and then after a very short period of time, it will return the value (the IP)

So the question is, how can I make getServerIp() function to wait untill the result is ready?

I tried to add connectionAttempts argument in callRemote but it didn't work. I was getting the same error.

Posted

You don't need to call the function each time you want the ip, because your server ip won't change anyway.

Posted

1st reply had nothing to do with what I asked.

I'll try to use a while cycle..

while theIP == false do

hm, I'll try.

Thanks Chronic

Posted
1st reply had nothing to do with what I asked.

I'll try to use a while cycle..

while theIP == false do

hm, I'll try.

Thanks Chronic

Oh wow I didn't even think of that

and no problem :)

Posted

Ok, tried with while cycle, but it freezes the server... uh no..

I got a good solution now.

Just call a function when the result is ready:

function getServerIp()

callRemote("http://www.nub.hj.cx/getServerIp.php",

function(value)

if (value ~= "ERROR") then

outputChatBox(type(value).." IP: "..value)

resultReady() -- Here's the function

return value

end

end)

outputChatBox("Returning False...")

return false

end

Posted

It's not returning anything, because it is trying to output theIP before it gets a response from getServerIp.

You should do what TAPL said, and just define theIP at the top of the script, because it isn't going to change.

addEventHandler ( "onResourceStart", resourceRoot, function ( ) 
    theIP = getServerIp() 
end ) 
  
addCommandHandler("getip", function() 
    outputChatBox(theIP) 
end ) 
  
function getServerIp() 
    callRemote("http://www.nub.hj.cx/getServerIp.php", function(value) 
        if (value ~= "ERROR") then 
            outputChatBox("Returning value...") 
            return value 
        end 
    end ) 
    outputChatBox("Returning False...") 
    return false 
end 
  

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