EZ4Patapon Posted May 18, 2019 Share Posted May 18, 2019 Hi, I'm trying to position a label at (SCREEN_WIDTH/2, SCREEN_HEIGHT) coordinates on the screen. Here's what I have: Quote GLOBAL.CHEATS_ENABLED = true GLOBAL.require( 'debugkeys' ) os_module = GLOBAL.require "os" --thx ultroman modimport "lib_ver.lua" local show_time = GetModConfigData("show_time") if not TUNING.SHOW_TIME then TUNING.SHOW_TIME = true AddPlayersAfterInit(function(inst) if inst == _G.ThePlayer and not show_time then return end inst.GetMyDisplayName = function(inst) return inst:GetDisplayName() end local label = inst.entity:AddLabel() label:SetFontSize(18) label:SetFont(_G.BODYTEXTFONT) label:SetPosition(20, 0, 0) --ERROR ('SetPosition' is nil) --label:SetUIOffset(0, 0, 0) ctime = os_module.date("*t") label:SetText(("%02d:%02d:%02d"):format(ctime.hour, ctime.min, ctime.sec)) label:SetColour(255/255,255/255,255/255) label:Enable(true) inst:DoPeriodicTask(1,function() ctime = os_module.date("*t") label:SetText(("%02d:%02d:%02d"):format(ctime.hour, ctime.min, ctime.sec)) end) end) end I have a few questions: Is label creation and the rest acceptable under AddPlayersAfterInit()? Or is there a different function/event hook for when the player is spawned? (I'm doing this as client-only) What's wrong with my usage of SetPosition()? Is it accessible from a different object/scope? Is there any documentation apart from http://dontstarveapi.com/?s=label ? For now, I grep through the scripts in the mods dir. FWIW, it works partly when I replace SetPosition with SetWorldOffset but that's not what I want...(label moves with player) Link to comment Share on other sites More sharing options...
EZ4Patapon Posted May 18, 2019 Author Share Posted May 18, 2019 Does label not have the SetPosition method? I searched the scripts dir and I found that SetPosition is only used with widgets which have labels as children. Link to comment Share on other sites More sharing options...
YakumoYukari Posted May 19, 2019 Share Posted May 19, 2019 Perhaps you can use Text Widget instead of the label? Link to comment Share on other sites More sharing options...
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