Jump to content

Add elementData to a GUI label


DRW

Recommended Posts

Posted

I've created some GUI labels attached to an image for a mining system, and it works well, it takes the elementData of a player and it changes the respective label with the number of the elementData I want to retrieve. The problem starts when joining, all the labels in the script appear and some of them bother a lot.

The essential part of the clientside script (Enough to know what happens since

local screenW, screenH = guiGetScreenSize() 
        interfven = guiCreateStaticImage(screenW - 192 - 10, (screenH - 111) / 2, 192, 111, ":imageretriever/zm.png", false) 
  
        lab = guiCreateLabel(10, 10, 64, 15, "Ununtrium:", false,  interfven) 
        guiSetFont(lab, "default-bold-small") 
        lab1 = guiCreateLabel(10, 25, 83, 15, "Ununquadium:", false,  interfven) 
        guiSetFont(lab1, "default-bold-small") 
        lab2 = guiCreateLabel(10, 40, 83, 15, "Ununpentium:", false,  interfven) 
        guiSetFont(lab2, "default-bold-small") 
        lab3 = guiCreateLabel(10, 55, 73, 15, "Ununhexium:", false,  interfven) 
        guiSetFont(lab3, "default-bold-small") 
        lab4 = guiCreateLabel(10, 70, 78, 15, "Ununseptium:", false,  interfven) 
        guiSetFont(lab4, "default-bold-small") 
        lab5 = guiCreateLabel(10, 85, 73, 16, "Ununoctium:", false,  interfven) 
        guiSetFont(lab5, "default-bold-small") 
        uut = guiCreateLabel(83, 10, 64, 15, "uut", false,  interfven) 
        guiSetFont(uut, "default-bold-small") 
        guiLabelSetColor(uut, 28, 255, 4) 
        uuq = guiCreateLabel(99, 25, 83, 15, "uuq", false,  interfven) 
        guiSetFont(uuq, "default-bold-small") 
        guiLabelSetColor(uuq, 181, 254, 4) 
        uup = guiCreateLabel(99, 40, 83, 15, "uup", false,  interfven) 
        guiSetFont(uup, "default-bold-small") 
        guiLabelSetColor(uup, 255, 198, 2) 
        uuh = guiCreateLabel(89, 55, 73, 15, "uuh", false,  interfven) 
        guiSetFont(uuh, "default-bold-small") 
        guiLabelSetColor(uuh, 255, 127, 1) 
        uus = guiCreateLabel(93, 70, 73, 15, "uus", false,  interfven) 
        guiSetFont(uus, "default-bold-small") 
        guiLabelSetColor(uus, 255, 48, 0) 
        uuo = guiCreateLabel(89, 85, 73, 15, "uuo", false,  interfven) 
        guiSetFont(uuo, "default-bold-small") 
        guiLabelSetColor(uuo, 255, 0, 0)    
  
addEventHandler ("onClientResourceStart",getResourceRootElement(getThisResource()),function() 
engineReplaceCOL ( col_floors, 3924 ) 
engineImportTXD ( txd_floors, 3924 ) 
engineReplaceModel ( dff_floors, 3924) 
local ununt= getElementData (localPlayer, "ununtrium") 
local ununq=getElementData (localPlayer, "ununquadium") 
local ununp=getElementData (localPlayer, "ununpentium") 
local ununh=getElementData (localPlayer, "ununhexium") 
local ununs=getElementData (localPlayer, "ununseptium") 
local ununo=getElementData (localPlayer, "ununoctium") 
guiSetText (uut, ""..ununt.."") 
guiSetText (uuq, ""..ununq.."") 
guiSetText (uup, ""..ununp.."") 
guiSetText (uuh, ""..ununh.."") 
guiSetText (uus, ""..ununs.."") 
guiSetText (uuo, ""..ununo.."") 
setDevelopmentMode (true) 
guiSetVisible (label,false) 
guiSetVisible (label2,false) 
guiSetVisible (label3,false) 
guiSetVisible (interfven,false) 
end) 
  
  

attempt to concatenate local 'ununt' (a boolean value)

What's wrong?

tJ5zeFm.gif

Proud owner and developer of ZNEXT: Aftermath.

Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience.

Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. 

Español, Pусский, Türk, عربى, Polski, Português

IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB

Posted (edited)

This means "ununtrium" element data is not set, or if it is, it is set to a boolean value, which means you need to tostring( ) the guiSetText like so:

guiSetText( uut, tostring( ununt ) ) 

And by the way, you don't need the quotes and stuff... just pass in the variable.

"" .. ununt .. "" 

Edited by Guest

If I helped you, please click the like button on the right ;) Thanks!

Posted
This means "ununtrium" element data is not set, or if it is, it is set to a boolean value, which means you need to tostring( ) the guiSetText like so:
guiSetText( uut, tostring( ununt ) ) 

And by the way, you don't need the quotes and stuff... just pass in the variable and tostring( ) it instead.

"" .. ununt .. "" 

Thank you very much!

tJ5zeFm.gif

Proud owner and developer of ZNEXT: Aftermath.

Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience.

Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. 

Español, Pусский, Türk, عربى, Polski, Português

IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB

Posted

You're welcome.

If you're still wondering why it's not returning anything other than a boolean (and it should be something else), then make sure the element data is set before the resource is started. In MTA 1.5 you can order the downloads so one resource starts before another one. Other than that, you could trigger a custom event client-side that will update the text after you have set the element data.

If I helped you, please click the like button on the right ;) Thanks!

Posted
You're welcome.

If you're still wondering why it's not returning anything other than a boolean (and it should be something else), then make sure the element data is set before the resource is started. In MTA 1.5 you can order the downloads so one resource starts before another one. Other than that, you could trigger a custom event client-side that will update the text after you have set the element data.

Wow, really? How can I order downloads?

tJ5zeFm.gif

Proud owner and developer of ZNEXT: Aftermath.

Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience.

Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. 

Español, Pусский, Türk, عربى, Polski, Português

IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB

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