Jump to content

setElementData / getElementData - Clientside


Recommended Posts

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 by Guest
Link to comment

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

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