havenphillip Posted August 4, 2018 Share Posted August 4, 2018 I just got a new computer I started having this problem. Seems like I've encountered this before but can't remember how to fix it but my numbers aren't showing up on start except for in one of the scripts. If I hit ESC then click somewhere random they appear and I can hit ESC again and it's fine. If I hit ESC and click randomly they appear but if I then hover the mouse over the words in the GUI they disappear again. How to fix this? Link to comment Share on other sites More sharing options...
havenphillip Posted August 4, 2018 Author Share Posted August 4, 2018 After I ESC and then click the mouse anywhere. You can see all the numbers are there: Link to comment Share on other sites More sharing options...
havenphillip Posted August 6, 2018 Author Share Posted August 6, 2018 It appears this format shows up on start: context:DrawText("Ammo: "..clip.. " | " ..Ammo, 20,108) ...but this does not: context:DrawText(string.format("Ammo: "..clip.. " | " ..Ammo), 20, 108, 100, 30, Text.VCenter+Text.Center) It works fine with ReepBlue's Luawerks so perhaps there's something missing in the Leadwerks Main.lua or Menu.lua which accounts for this? I just don't know where to look. Link to comment Share on other sites More sharing options...
macklebee Posted August 7, 2018 Share Posted August 7, 2018 Both of those work fine, even though there is no reason to use 'string.format()' in your example. example: window = Window:Create("example",0,0,400,400) context = Context:Create(window) world = World:Create() light = DirectionalLight:Create() light:SetRotation(45,45,0) camera = Camera:Create() camera:SetPosition(0,0,-3) counter = 1400 toggle = 0 myfont = Font:Load("Fonts/arial.ttf", 24) context:SetFont(myfont) clip = 10 Ammo = 100 while not window:KeyHit(Key.Escape) do if window:Closed() then return false end if toggle==1 then counter = counter + 10 end if toggle==0 then counter = counter - 10 end if counter>=1400 then toggle = 0 end if counter<=10 then toggle = 1 end Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:SetColor(1,0,0,.5) context:DrawRect(38,30,300,300,1,30) context:DrawText(string.format("%.0f",counter),38,30,300,300,Text.VCenter+Text.Center) context:SetColor(1,1,1,1) context:DrawText("Ammo: "..clip.. " | " ..Ammo, 20,108) context:DrawText(string.format("Ammo: "..clip.. " | " ..Ammo), 20, 248, 300, 50, Text.VCenter+Text.Center) context:SetBlendMode(Blend.Solid) context:Sync(true) end At this point, you really need to provide something that we can try that replicates your issue. There is a reason no one has replied to your post - there's not enough information provided for anyone to do anything other than guess at what you are doing wrong. Actually provide a simple example that shows the problem that people can try and more than likely someone can help you. 1 Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
havenphillip Posted August 7, 2018 Author Share Posted August 7, 2018 Thanks for the reply. I just tried your code here. Same problem. Not sure why but it's not working for me with the standard Leadwerks Main.lua. The only format that shows up is: context:DrawText("Ammo: "..clip.. " | " ..Ammo, 20,108) If I use Luawerks instead it works fine, they all show up. So if you have bought Luawerks you can switch the Main.lua back and forth and see. That's the best replication I have right now. I presumed someone would have encountered this and I know a lot of you guys can just troubleshoot these things in your head. Not sure what it is about the Luawerks system that makes it work that is missing in the original. Here's one of my scripts where the text isn't showing up in case you want to see if I'm doing something wrong: Script.overlayPath = "" --path "Texture" "Tex file (*tex):tex" Script.timeBarColor = Vec4(255,128,0,255) --color "Timebar Color" Script.fontColor = Vec4(1,1,1,0.8) -- color "Font Color" Script.maxTime = 150 --int "Countdown Time" Script.radius = 35 --int "Radius" Script.cirPos = Vec2(100,180) --Vec2 "Circle Position" function Script:Start() self.font = Font:Load("Fonts/arialbd.ttf", 10) self.player = self.entity:GetParent() self.camera = self.player.script.camera self.endtime = 0 self.timer = self.maxTime if self.overlayPath ~= "" then self.overlay = Texture:Load(self.overlayPath) end end function Script:UpdateWorld() self.timer = self.timer - Time:GetSpeed()/100 if self.timer < self.endtime then self.timer = 0 self:GameOver() end end function Script:GameOver() self.player.script.health = 0 self.player.script:Kill() self.entity:Release() end function Script:PostRender(context) local x = 0 local y = 0 local r = self.radius local G = 1000 local countdown = self.timer/self.maxTime local p = self.radius + self.radius/5 w = context:GetWidth()/context:GetWidth() + self.cirPos.x h = context:GetHeight()/2 + self.cirPos.y context:SetBlendMode(1) --draw overlay if self.overlayPath ~= nil then context:SetColor(1,1,1,0.45) context:DrawImage(self.overlay, w-p, h-p, p*2, p*2) end -- draw circle for k = 0, G do a = 360 / G * k *(countdown) X = -(r * Math:Sin(a)) + x Y = -(r * Math:Cos(a)) + y context:SetColor(self.timeBarColor) context:DrawRect(X + w, Y + h, X/5 , Y/5, 1) end --draw text context:SetColor(self.fontColor) context:SetFont(self.font) context:DrawText(string.format("%.0f",self.timer), w-14, h-14, 30, 30, Text.VCenter+Text.Center) end Link to comment Share on other sites More sharing options...
Jazz Posted August 7, 2018 Share Posted August 7, 2018 5 hours ago, macklebee said: Both of those work fine, even though there is no reason to use 'string.format()' in your example. Drawtext is bugged when used with the built in GUI. Looks like a gui redraw issue. The following shows the problem. Hit escape for menu, then click outside the buttons. import("Scripts/Menu.lua") window = Window:Create("example",0,0,800,600) context = Context:Create(window) world = World:Create() light = DirectionalLight:Create() light:SetRotation(45,45,0) camera = Camera:Create() camera:SetPosition(0,0,-3) counter = 1400 toggle = 0 myfont = Font:Load("Fonts/arial.ttf", 16) context:SetFont(myfont) clip = 10 Ammo = 100 local gamemenu = BuildMenu(context) gamemenu.newbutton:SetText("RESUME GAME") window:HideMouse() while window:Closed()==false do if gamemenu:Update()==false then return end if toggle==1 then counter = counter + 10 end if toggle==0 then counter = counter - 10 end if counter>=1400 then toggle = 0 end if counter<=10 then toggle = 1 end if gamemenu:Hidden() then Time:Update() world:Update() end world:Render() context:SetBlendMode(Blend.Alpha) context:SetColor(1,0,0,.5) context:DrawRect(38,30,300,300,1,30) context:SetColor(0,1,1,1) context:DrawText(string.format("Ammo1: "..clip.. " | " ..Ammo), 100, 80) context:SetColor(1,0,0,.5) context:DrawText(string.format("%.0f",counter),38,30,300,300,Text.VCenter+Text.Center) context:SetColor(1,1,1,1) context:DrawText(string.format("Ammo2: "..clip.. " | " ..Ammo), 30, 100, 300, 250, Text.VCenter+Text.Center) context:SetColor(0,1,1,1) context:DrawText(string.format("Ammo3: "..clip.. " | " ..Ammo), 100, 300) context:SetBlendMode(Blend.Solid) context:Sync(true) end 2 1 --- Scott Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060 Link to comment Share on other sites More sharing options...
macklebee Posted August 8, 2018 Share Posted August 8, 2018 This above is what was needed to be provided to help troubleshoot. An example that demonstrates the issue. So from the looks of it, anything that uses the undocumented, new DrawText() with the extended parameters for centering within a given rectangle does not play well not just with the gamemenu script but any gui element you create. As a test I created a simple program that created a label and then just performed the new DrawText() version that was not part of the label/gui. The new version of DrawText() if not part of the gui for some reason will be hidden. So what I found is if I just simply redraw the gui's base whether its hidden or not, the new DrawText() will show properly. Example: window = Window:Create("Label Example",0,0,800,600,Window.Titlebar + Window.Center) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:SetPosition(0,0,-3) light = DirectionalLight:Create() light:SetRotation(35,35,0) box = Model:Box() box:SetColor(1,0.5,0,1) gui = GUI:Create(context) base = gui:GetBase() base:SetScript("Scripts/GUI/panel.lua") base:SetObject("backgroundcolor",Vec4(0,0,0,0.5)) colorlabel = Widget:Create("Example", 20, 20, 300, 80, base, "Scripts/GUI/Label.lua") colorlabel:SetString("align","Center") colorlabel:SetString("valign","Center") colorlabel:SetBool("border",true) gui:Hide() toggle = 0 clip = 10 Ammo = 100 counter = 1400 while not window:KeyHit(Key.Escape) do if window:Closed() then return false end box:Turn(Time:GetSpeed()*0.5,Time:GetSpeed()*0.3,0) if window:KeyHit(Key.Space) then toggle = 1 - toggle if toggle == 1 then gui:Show() else gui:Hide() end end Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:SetColor(1,0,0,.5) context:DrawText(string.format("Ammo1: "..clip.. " | " ..Ammo), 100, 80) context:DrawText("Press SPACE to toggle gui", 100, 300) context:DrawText(counter,38,30,300,300,Text.VCenter+Text.Center) context:SetBlendMode(Blend.Solid) --base:Redraw()--uncomment this and you will draw the new DrawText() version above context:Sync() end So based on that little example, all we need to fix the OP issue is to redraw the gamemenu's gui base. So if you add the redraw code to Menu.lua, it will draw properly everything in Jazz's example. So in the GameMenu:Update() function in the Menu.lua script, before it returns true, add the following code to line 480: gui:GetBase():Redraw() Edit -- this is admittedly a work around, but a fairly simple fix for something that Josh might not ever get around to resolving with DrawText() - especially since this version of DrawText() isn't officially documented. Edit-- Or if you don't want to edit the Menu.lua script, then in the example Jazz provided, just add this before the context:Sync(true): gamemenu.gui:GetBase():Redraw() and everything appears to be drawn properly. This should also fix the problem the OP is having if he adds it to the default Main.lua as well. 2 Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
havenphillip Posted August 8, 2018 Author Share Posted August 8, 2018 Ah yes! Thanks. That works. Link to comment Share on other sites More sharing options...
Josh Posted August 9, 2018 Share Posted August 9, 2018 It looks like maybe some clipping plane stuff is left active after the GUI renders. 1 My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
macklebee Posted August 9, 2018 Share Posted August 9, 2018 10 hours ago, Josh said: It looks like maybe some clipping plane stuff is left active after the GUI renders. So if that was the case, then shouldn't that also prevent just a normal DrawText() from appearing as well? Because it doesn't. Does the new DrawText() have a different drawing order than a normal DrawText()? Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted August 10, 2018 Share Posted August 10, 2018 What is a "normal" DrawText command? 1 My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
macklebee Posted August 10, 2018 Share Posted August 10, 2018 14 minutes ago, Josh said: What is a "normal" DrawText command? The normal would be just 'context:DrawText("text",x,y)'. This version of DrawText() is not affected by the creation of gui element. But if you use 'context:DrawText("text",x,y,w,h,style)' and have created a gui element, it will be hidden - unless of course you redraw the gui base as shown in my example. So for whatever reason, the two versions of DrawText() react differently depending on whether a gui element exists. Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted August 10, 2018 Share Posted August 10, 2018 Oh yeah, you are right, there are two overloads. I don't know if the new overload will work correctly if you use it outside of a GUI script. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
macklebee Posted August 10, 2018 Share Posted August 10, 2018 well, it does if you just redraw the gui base as shown in my above example... I don't know if that's necessarily a good thing or not or will cause a problem with something else, but it appears to get around the problem at the moment. also it works just fine when you don't have any gui elements... Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted August 10, 2018 Share Posted August 10, 2018 Can I close this? The bottom line is, don't use the new DrawText overload. I could change the name internally in the future, because this only gets called by a call to GUI::DrawText(). The GUI then checks to see if it is attached to a 3D context or to an OS Window and it proceeds from there. 1 My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts