Core Posted September 24, 2017 Share Posted September 24, 2017 Is it possible to type word in game, and store it in a variable? Like old school text games etc. Ironic, I never was very good at C64 basic, but even I was able to do that Now it is not so easy. Quote Link to comment Share on other sites More sharing options...
Core Posted September 24, 2017 Author Share Posted September 24, 2017 (edited) Ok, I found TextArea and TextField scripts from GUI scripts. But did not know where to start with those. I know, I'm thick headed, but how those GUI widgets work? Or how I use them? Example, how to do this: I have terminal in my game world. When player uses/interacts with it, it opens a menu, where is only one thing, area where player can type text. When player hits enter, it stores what ever player typed to a variable. Again, I'm not looking for a full code, just pointers to the right direction and where to even start, thanks! Edit. So I found this. I think it is what I need... Edited September 24, 2017 by Core added link Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted September 24, 2017 Share Posted September 24, 2017 josh posted a example chat program. i think you can get your answers there if not tell me and ill show you.https://www.leadwerks.com/community/topic/16341-chat-example/Hint:local s = interface.textbox:GetText() 1 Quote Link to comment Share on other sites More sharing options...
Core Posted September 24, 2017 Author Share Posted September 24, 2017 Oh, thank you very much @GorzenDev! I will look in to it this evening! Quote Link to comment Share on other sites More sharing options...
Core Posted September 25, 2017 Author Share Posted September 25, 2017 Thank you again for your help, @GorzenDev, I just got working the first iteration of the interface. This was a big milestone for me! I might never have looked Josh's chat example without your tip. One question arised though. How can I make/add own modified widgets or load modified script file to default ones? Now I just modified the stock ones (made backups). 1 Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted September 25, 2017 Share Posted September 25, 2017 38 minutes ago, Core said: Thank you again for your help, @GorzenDev, I just got working the first iteration of the interface. This was a big milestone for me! I might never have looked Josh's chat example without your tip. One question arised though. How can I make/add own modified widgets or load modified script file to default ones? Now I just modified the stock ones (made backups). you would need to have the widget point to your script. Widget:Create("text", x, y, w, h, parent, "scriptfile"); that would create a custom widget with your own behaviour. change values in your script with: widget:SetBool("variableName", false) widget:GetBool("variableName") widget:SetFloat("variableName", 0.0) widget:GetFloat("variableName") widget:SetString("variableName", "value") widget:GetString("variableName") there are more Get/Set functions in the documentation:https://www.leadwerks.com/learn?page=API-Reference_Object_Widget_Create alternatively you could do: newbutton = Widget:Button("button",10,10,300,20, gui:GetBase()) newbutton:SetSript("Scripts/GUI/customButton.lua") 1 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted September 28, 2017 Share Posted September 28, 2017 On 9/25/2017 at 3:56 AM, Core said: Thank you again for your help, @GorzenDev, I just got working the first iteration of the interface. This was a big milestone for me! I might never have looked Josh's chat example without your tip. One question arised though. How can I make/add own modified widgets or load modified script file to default ones? Now I just modified the stock ones (made backups). I love love love our GUI implementation. Using a per-widget script was sooooooo smart because it provides this extreme flexibility. Quote 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...
Core Posted September 29, 2017 Author Share Posted September 29, 2017 On 28.9.2017 at 8:45 AM, Josh said: I love love love our GUI implementation. Using a per-widget script was sooooooo smart because it provides this extreme flexibility. Yup, some powerful stuff there in Leadwerks! Quote Link to comment Share on other sites More sharing options...
Core Posted September 29, 2017 Author Share Posted September 29, 2017 Another one with this... I try to autoscroll my text area and made this script: local i local offset = 10 for i=1,offset do self.scroll1 = self.slider[0]:GetSliderValue() System:Print(self.scroll1) self.scroll2 = (self.scroll1+1) self.slider[0]:SetSliderValue(self.scroll2) System:Print(self.scroll2) It works, unless there are more new lines than one. For some reason, it just won't scroll all the way down automatically if there are more lines than one added to the text area widget at the same time. I CAN scroll all the way down with mouse though. I tried with the unmodified TextArea script too, no luck. System:Print prints slider values long after the scrolling has stopped, so it is not that there is too few loops. Strange though, that no matter what "offset" I put, the result is the same. So how I can make text area scroll automatically all the way down when text is added to it? Can I "emulate" mouse wheel somehow maybe? Quote Link to comment Share on other sites More sharing options...
Josh Posted September 30, 2017 Share Posted September 30, 2017 7 hours ago, Core said: Another one with this... I try to autoscroll my text area and made this script: local i local offset = 10 for i=1,offset do self.scroll1 = self.slider[0]:GetSliderValue() System:Print(self.scroll1) self.scroll2 = (self.scroll1+1) self.slider[0]:SetSliderValue(self.scroll2) System:Print(self.scroll2) It works, unless there are more new lines than one. For some reason, it just won't scroll all the way down automatically if there are more lines than one added to the text area widget at the same time. I CAN scroll all the way down with mouse though. I tried with the unmodified TextArea script too, no luck. System:Print prints slider values long after the scrolling has stopped, so it is not that there is too few loops. Strange though, that no matter what "offset" I put, the result is the same. So how I can make text area scroll automatically all the way down when text is added to it? Can I "emulate" mouse wheel somehow maybe? I think you will need to post a working example to get any help with this. The textarea widget was pretty difficult to write, and is only meant to be a static display of text, not a full text editor. Scintilla is better suited for that. Quote 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...
Core Posted September 30, 2017 Author Share Posted September 30, 2017 Yes, I think I can work with this, it is allready working well enough for what I have in mind. I might create new text area widget for multiline texts instead off adding to the old one. All in all, this is one final piece, soon I can start to create actual gameplay content and assets to finally create something you can actually play. I think I'll start project thread and post details of my game project. And demo. Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted September 30, 2017 Share Posted September 30, 2017 honestly looking at the vanilla TextArea.lua it looks like it should support what you want. try something like below. (not tested it) function Script:AddText(text) self.updateslidersneeded=true local morelines = text:split("\n") local gui=self.widget:GetGUI() local n for n=1,#morelines do self.lines[#self.lines+1] = morelines[n] self.linewidth[#self.lines] = gui:GetTextWidth(morelines[n]) self.maxlinewidth = math.max(self.maxlinewidth,self.linewidth[#self.lines]) end --try something like this self:MouseWheel(#morelines) end Quote Link to comment Share on other sites More sharing options...
Core Posted September 30, 2017 Author Share Posted September 30, 2017 Thanks, I actually figured out what was wrong... Text Area widget needs to be in focus for scrolling to work! I switched focus too quicly back to text input field so when I delayed the switch back to input field, scrolling was able to finish! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.