Animan99 Posted June 22, 2015 Share Posted June 22, 2015 Hi. I am writing my own (First) phone system, i am learning LUA about 2 months. I advance nicely with the phone, but i have a little problem with the chat part. When i click on the "send" button, this code runs: -- this code adds a value to the table, that i will loop through in the next code. function sendCallMSG(msg) for _, player in pairs(getElementsByType("player")) do targetPlayer = player msgFrom = getElementData(localPlayer, "phoneNumber") msgTo = getElementData(targetPlayer, "phoneNumber") theMsg = tostring(msg) callMessages[#callMessages + 1] = theMsg setElementData(targetPlayer, "char.tempCall", {msgFrom, msgTo, theMsg}) renderData.msgCounter = renderData.msgCounter + 1 --renderData.currentRow = renderData.currentRow + 1 break end end And the second code loops the "callMessages" table, and write out the value: if getElementData(localPlayer, "phone") == "goingCall" then dxDrawImage(X, Y + 35, Width, Height, "files/ongoingcall.png") renderData.smsLatestLine = renderData.currentRow + renderData.maxRow - 1 for k,v in ipairs(callMessages) do if k >= renderData.currentRow then if k <= renderData.smsLatestLine and v then renderData.smsDrawX = X + 70 renderData.smsDrawY = Y + 125 + (renderData.sorokKozKihagyas * (renderData.uzenetSzamolo - 1)) -- this is the important thing, this moves the value, but my problem is when i click again the send button all the values are moving with this. I want that the values are move 10 pixels down from the previous value, but all the messages are moving. if vanUjSzoveg == true then renderData.smsDrawY = renderData.uzenetSzamolo * 10 end dxDrawText(string.gsub(v, "_", " "), renderData.smsDrawX, renderData.smsDrawY, 50, 0, tocolor(255, 255, 255, 255), 2, "arial", "left", "top", false, true, true) end end end end So, basically, I want that the values are move 10 pixels down from the previous value. Thank you, i will be so glad if you guys can help me Link to comment
jingzhi Posted June 22, 2015 Share Posted June 22, 2015 Hi. I am writing my own (First) phone system, i am learning LUA about 2 months. I advance nicely with the phone, but i have a little problem with the chat part. When i click on the "send" button, this code runs: -- this code adds a value to the table, that i will loop through in the next code. function sendCallMSG(msg) for _, player in pairs(getElementsByType("player")) do targetPlayer = player msgFrom = getElementData(localPlayer, "phoneNumber") msgTo = getElementData(targetPlayer, "phoneNumber") theMsg = tostring(msg) callMessages[#callMessages + 1] = theMsg setElementData(targetPlayer, "char.tempCall", {msgFrom, msgTo, theMsg}) renderData.msgCounter = renderData.msgCounter + 1 --renderData.currentRow = renderData.currentRow + 1 break end end And the second code loops the "callMessages" table, and write out the value: if getElementData(localPlayer, "phone") == "goingCall" then dxDrawImage(X, Y + 35, Width, Height, "files/ongoingcall.png") renderData.smsLatestLine = renderData.currentRow + renderData.maxRow - 1 for k,v in ipairs(callMessages) do if k >= renderData.currentRow then if k <= renderData.smsLatestLine and v then renderData.smsDrawX = X + 70 renderData.smsDrawY = Y + 125 + (renderData.sorokKozKihagyas * (renderData.uzenetSzamolo - 1)) -- this is the important thing, this moves the value, but my problem is when i click again the send button all the values are moving with this. I want that the values are move 10 pixels down from the previous value, but all the messages are moving. if vanUjSzoveg == true then renderData.smsDrawY = renderData.uzenetSzamolo * 10 end dxDrawText(string.gsub(v, "_", " "), renderData.smsDrawX, renderData.smsDrawY, 50, 0, tocolor(255, 255, 255, 255), 2, "arial", "left", "top", false, true, true) end end end end So, basically, I want that the values are move 10 pixels down from the previous value. Thank you, i will be so glad if you guys can help me I don't really understand what are you trying to do here, but it seems like the message will be sent to all the players in the server Link to comment
Animan99 Posted June 22, 2015 Author Share Posted June 22, 2015 when i send a message it moves correctly, but when i send another one, the second and the first message are at the same position, i want that the second msg move down 10 px from the previous one. http://kepfeltoltes.hu/150622/mta-scree ... es.hu_.png on the photo you can see the 2 messages are at the same pos. Sorry for my bad english, hope you can understand now. (Yes, sends to everyone, i didn't finished it yet) Link to comment
Dealman Posted June 22, 2015 Share Posted June 22, 2015 Can't you just insert linebreaks using "Message1\nMessage2"...? Link to comment
Animan99 Posted June 22, 2015 Author Share Posted June 22, 2015 it loops through callMessages table, and i dont know how to separate them. Can you explain it, how to use in my code ? Link to comment
Dealman Posted June 22, 2015 Share Posted June 22, 2015 In that case store a variable outside of the for loop which increases after every index. exampleIndex = 10 for k, v in ipairs() do exampleIndex = exampleIndex+10 -- 10 -> 20 -> 30 -> 40 etc... end Link to comment
Animan99 Posted June 22, 2015 Author Share Posted June 22, 2015 When i use this, both messages are moves in the table. i want always the last moves down from the previous 10 pixels. Link to comment
Animan99 Posted June 22, 2015 Author Share Posted June 22, 2015 if you can tell me another way of making this chat part, it will good, but i have no idea how to do this. Link to comment
jingzhi Posted June 22, 2015 Share Posted June 22, 2015 if you can tell me another way of making this chat part, it will good, but i have no idea how to do this. x,y,z = 0,0,0 for k, v in ipairs() do y = y + 10 --Script continues.. end For a better way, i think you should not use dxDrawText for the messages Link to comment
Animan99 Posted June 22, 2015 Author Share Posted June 22, 2015 This isn't my problem. My problem with the loop, because i use for loop to get the value of the tables and if i use this, the messages are all moves. i want that when i send a message that message down from the previous one. All the messages are in one table, that is why i ant separate them from eachother. Link to comment
jingzhi Posted June 22, 2015 Share Posted June 22, 2015 This isn't my problem. My problem with the loop, because i use for loop to get the value of the tables and if i use this, the messages are all moves. i want that when i send a message that message down from the previous one. All the messages are in one table, that is why i ant separate them from eachother. Why don't you use a memo you start from a new line with each message? Link to comment
Animan99 Posted June 23, 2015 Author Share Posted June 23, 2015 I made it with GUI, but i cannot destroy it. When i click on the send button, creates a GUI label. if i try to destroy it, the last label dissapears, the rest of messages are stay there. Thanks for your help Link to comment
jingzhi Posted June 23, 2015 Share Posted June 23, 2015 I made it with GUI, but i cannot destroy it. When i click on the send button, creates a GUI label. if i try to destroy it, the last label dissapears, the rest of messages are stay there. Thanks for your help You're welcome, don't hesitate to ask if you have further problems Link to comment
Animan99 Posted June 23, 2015 Author Share Posted June 23, 2015 my next problem is i cannot destroy the GUI When i click on the send button, creates a GUI label. if i try to destroy it, the last label dissapears, the rest of messages are stay there. Link to comment
Dealman Posted June 23, 2015 Share Posted June 23, 2015 Post your code and we might be able to help you Link to comment
Animan99 Posted June 23, 2015 Author Share Posted June 23, 2015 I just solved it Thx for your help guys i have a few more question, ill ask later. Link to comment
Animan99 Posted June 23, 2015 Author Share Posted June 23, 2015 I have a problem. i have the chat part with GUI and this is my problem: http://kepfeltoltes.hu/150623/mta-scree ... es.hu_.png you can see some messages are out of the phone. i can do with dxSetRenderTarget but its GUI and i dont know how to do that are the messages are scrollable and inside the phone. Please, help me Thanks Link to comment
jingzhi Posted June 24, 2015 Share Posted June 24, 2015 I have a problem. i have the chat part with GUI and this is my problem: http://kepfeltoltes.hu/150623/mta-scree ... es.hu_.pngyou can see some messages are out of the phone. i can do with dxSetRenderTarget but its GUI and i dont know how to do that are the messages are scrollable and inside the phone. Please, help me Thanks I think you should use memo instead of labels Link to comment
Animan99 Posted June 24, 2015 Author Share Posted June 24, 2015 and how to make memo like dxSetRenderTarget? and how to make a memo scrollable? Link to comment
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