Jump to content

setElementData / getElementData - Clientside


Recommended Posts

Posted (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 by Guest
Posted

You are trying to use pHealth in another functions right?

Won't work because pHealth only exists inside func2.

Because it's local.

Posted

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.

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

Posted

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.

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