'LinKin Posted May 24, 2014 Share Posted May 24, 2014 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. Link to comment
TAPL Posted May 24, 2014 Share Posted May 24, 2014 You don't need to call the function each time you want the ip, because your server ip won't change anyway. Link to comment
Chronic Posted May 24, 2014 Share Posted May 24, 2014 One way you could do it is if type ( theIP ) == "boolean" then setTimer (...) or something like that.. Good luck Link to comment
'LinKin Posted May 24, 2014 Author Share Posted May 24, 2014 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 Link to comment
Chronic Posted May 24, 2014 Share Posted May 24, 2014 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 Link to comment
'LinKin Posted May 24, 2014 Author Share Posted May 24, 2014 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 Link to comment
xXMADEXx Posted May 24, 2014 Share Posted May 24, 2014 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 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now