unknooooown Posted July 28, 2011 Share Posted July 28, 2011 (edited) Hi. Got a small problem with some code on my clientside script. Here is an example of my problem. If I try to output the line in func2, it returns false, but if I try to output it in the first function, it works. What am I doing wrong here? EDIT: Oh right.. The (message) is from serverside. function func1(message) local pHealth = message setElementData ( getLocalPlayer(), "pHealth", pHealth, true ) end function func2() local pHealth = tostring(getElementData(getLocalPlayer(),"pHealth")) end Thank you. Edited July 28, 2011 by Guest Link to comment
JR10 Posted July 28, 2011 Share Posted July 28, 2011 You are trying to use pHealth in another functions right? Won't work because pHealth only exists inside func2. Because it's local. Link to comment
unknooooown Posted July 28, 2011 Author Share Posted July 28, 2011 Thank you for the quick reply. Have a look at the code again. I am adding the key pHealth and a value to pHealth in the first function. In the second function I am trying to retrieve the value again, using getElementData. I have done it the exact same way in a serverside script, where it works. Link to comment
JR10 Posted July 28, 2011 Share Posted July 28, 2011 function func1(message) local pHealth = message setElementData ( getLocalPlayer(), "pHealth", pHealth, true ) end function func2() local pHealth = tostring(getElementData(getLocalPlayer(),"pHealth")) outputChatBox(pHealth) end It will work, but if you tried to do it outside func2 it won't work, because the variable pHealth in func2 is local, where it exists only inside it's block (function func2 in this situation). Link to comment
unknooooown Posted July 28, 2011 Author Share Posted July 28, 2011 Ty again. I already tried the exact same thing. I have been trying to make it work for about 2 hours now. I will only be using pHealth in func2, but it returns false when I do it like above. 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