lxFirebal69xl Posted February 8, 2015 Share Posted February 8, 2015 So a while ago, I got this script going that makes so the player presses E text will show up, my problem is, if the player clicks on 2 objects at the same time, the text will overlap itself Script Script.ObjectDescription = "" --String "Object Description" Script.DisplayTimeMax = 5000 --Int "Display time" Script.Used = "0" Script.DisplayTime = 0 Script.DisplayEnabled = false local font1 = Font:Load("Fonts/True Lies.ttf", 20) function Script:Use(context) self.Used = "1" self.CurrentTime = Time:GetCurrent() self.DisplayTime = Time:GetCurrent() + self.DisplayTimeMax end function Script:PostRender(context) if self.Used == "1" then App.context:SetBlendMode(Blend.Alpha) App.context:SetFont(font1) self.DisplayEnabled = true if self.DisplayEnabled == true then if self.DisplayTime > Time:GetCurrent() then App.context:SetColor(255,255,255) context:DrawText(self.ObjectDescription, 100, 600) else self.DisplayEnabled = false self.Used = "0" end end App.context:SetBlendMode(Blend.Solid) end end And my problem Quote Link to comment Share on other sites More sharing options...
Rick Posted February 8, 2015 Share Posted February 8, 2015 I assume you attach this script to all the objects you want to have this in your game? The problem with that is exactly this . I think you really want this text to be displayed from the player script itself. These object scripts should just contain what you want to say, then the picking should happen in the player script, and from the entity picked you get it's script's ObjectDescription variable and store that in your player script and draw that in post render. This way if you click 2 objects the first one will be overwritten with the second because you are storing it in a player script variable. So in other words these object scripts should only contain data and not the functionality of displaying that data. The player script should get the data from these objects via picking them and be responsible for being the 1 central place to display that data on screen. You can get script data from entities you picked via the script variable they would have (if it's not nil) pickedEntity.script.ObjectDescription [edit] If your script needs to do something special and unique then put that in a Use function but the act of displaying text on screen isn't special and unique so your objects probably shouldn't do that. Let the player script do that from the object information, especially if an issue like this can happen with your type of game. Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted February 8, 2015 Author Share Posted February 8, 2015 I assume you attach this script to all the objects you want to have this in your game? The problem with that is exactly this . I think you really want this text to be displayed from the player script itself. These object scripts should just contain what you want to say, then the picking should happen in the player script, and from the entity picked you get it's script's ObjectDescription variable and store that in your player script and draw that in post render. This way if you click 2 objects the first one will be overwritten with the second because you are storing it in a player script variable. So in other words these object scripts should only contain data and not the functionality of displaying that data. The player script should get the data from these objects via picking them and be responsible for being the 1 central place to display that data on screen. You can get script data from entities you picked via the script variable they would have (if it's not nil) pickedEntity.script.ObjectDescription [edit] If your script needs to do something special and unique then put that in a Use function but the act of displaying text on screen isn't special and unique so your objects probably shouldn't do that. Let the player script do that from the object information, especially if an issue like this can happen with your type of game. Allright, I'll mess around with it, see what happens. Will tell you if I do it. Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted February 8, 2015 Author Share Posted February 8, 2015 I'm sorry, I'm really bad at this, I can't figure it out Quote Link to comment Share on other sites More sharing options...
Rick Posted February 8, 2015 Share Posted February 8, 2015 Attach your player script and I can help modify it to make it work. Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted February 8, 2015 Author Share Posted February 8, 2015 Here you go.FPSPlayer.lua Quote Link to comment Share on other sites More sharing options...
Rick Posted February 9, 2015 Share Posted February 9, 2015 So your object file just becomes Script.ObjectDescription = "" --string "Object Description" function Script:GetText() return self.ObjectDescription end In the attached FPSPlayer.lua you can search for RLP to find the code I added. There are a few sections and I do begin/end and everything in-between is what I changed. Now only 1 text at a time will display and it'll still go away after so long. FPSPlayer.lua Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted February 9, 2015 Author Share Posted February 9, 2015 Thank you very much, that made it work 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.