• Need suggestion on how to proceed
    28 replies, posted
I want to make a system where I can write and edit a file that the info will be used on the client side. Right now I have it so I have a txt file and when I need the info, it reads the txt file. I would get that data and send that data to the client using usermessages. But the thing is, the data I'm sending over has over 1000 characters and possibly more will be added.... How else can I do this? Yes, I've thought about making the string in the client so I don't even need to send the data over instances, but I don't want to have to change the client side lua.
What kind of system are you talking about? Flat file saving or PData Saving? Is this some kind of money system of inventory? It would be great to know what you're using this for to get a better idea of where to start with this.
I'm basically making a MOTD that I can change on a daily bases without having to update the FastDL stuff... Basically I have a txt file that is full of these Rules, another txt file that has a message for the week, another txt file for the admins on the server, etc.
You can probably resource.AddFile the file from the server sonthe client gets it, then read it from clientside and store it in a variable. Once that is done, delete the file so it it won't conflict if you update the file another time.
Okay that sounds all nice and dandy but I was wondering if there was a way where no one would have to download anything more than once... I will resort to this if there's no other way, though.
You can split the content of the data and send it to the client, which would piece it back.
What do you mean by that?
Take your giant string, chop it up into substrings and send seperate usermessages, you can probably even include some sort of index with the usermessage. Once the usermessage is received, it'll take the index and and the string received, then peice up the original message.
Alright I thought I about doing that but thought it would be very inefficient. I guess it's the only way and I'll try that out, thanks!
It wouldn't be that inefficient. The amount of time it would take to send multiple usermessages containing parts of the MoTD wouldn't make much of an impact at all. [lua]--------- -- Server --------- local bitsize = 32 -- I'm not sure exactly how much text can be sent alongside pointers so you can toy with this number local bits = {} function GetMoTD() local txt = file.Read("motd.txt") bits = {} -- Clears the table in case the function is ran again (loading a new motd) while (string.len(txt) > bitsize) do local bit = string.sub(txt, 1, bitsize) table.insert(bits, bit) txt = string.sub(txt, bitsize + 1) end end function SendMoTD(pl) for k, v in pairs(bits) do umsg.Start("MoTDBit", pl) umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them umsg.String(v) umsg.End() end end --------- -- Client --------- local bits = {} usermessage.Hook("MoTDBit", function(u) local bitnum = u:ReadShort() local numbits = u:ReadShort() local bit = u:ReadString() bits[bitnum] = bit if (#bits == numbits) then -- Stitch the MoTD local motd = table.concat(bits, "") /* This is where you would put code to open the HTML */ bits = {} -- Clear the table so the MoTD can be sent again if it's changed or needs to serve a different purpose end end)[/lua] This should do it for you.
Isn't a single character 1 byte? If it is: code's just a bit misleading, because you're sending 32 bytes of information, not 32 bits. Ends up being 256 bits. Either way, that's a nice script you've got there. [SUB]A practise several people have rated me dumb for defending :([/SUB]
I'll have to toy with that to see what the highest # I can set the variable bitsize, I'll get back to you with that answer if you're curious, wizardsbane. [editline]3rd May 2012[/editline] Oh and thanks for the example code! Really appreciated
Well, by bit I mean 'chunk', not differentiating between bits/bytes. I see where you're coming from though.
I've set up my code and haven't had a chance to test it because my server is out of date and having trouble updating it... ANYWAYS, I just ran into this function called SetGlobalString... I wonder, could I just use that to set the info I need into these global strings? Or is there a capacity limit (or w.e you wanna call it) on these GlobalStrings?
SetGlobalString is basically doing GetWorldEntity:SetNWString(name, value). As you know, SetNW functions use usermessages, so it would have the same limits.
Ah, alright.
Nvm. [editline]3rd May 2012[/editline] Okay so I have the bitsize to 200 and when I'm doing the GetMoTD() function I made it print the bits table and it cuts out right before the end. Then when it sends that table over to the client, it pieces it together, but also cuts out a chunk of it. Then I repeated the GetMoTD() and SendMoTD() function for seperate files ( admin list / motw ) and since those two have less characters than the bitsize it doesn't even include any of those files.. Can you help me fix it? I'm having trouble understanding each specific part itself, otherwise I'd fix it myself. Incase it's needed (full code): [url]http://pastebin.com/6KtnnNW3[/url]
Halp?
If you want an easily edited MOTD, here's another solution, you always can make the MOTD a webpage, and make the webpage the MOTD. Then just edit the webpage and it will change. You need a website for this method, but a forum or something would work.
I thought about that but I have multiple servers and don't want like 10 extra pages. I tried to fix it myself and I came up with this: [lua] function GetMoTD() local txt = file.Read("motd/rules.txt") bits = {} -- Clears the table in case the function is ran again (loading a new motd) while (string.len(txt) > bitsize) do local bit = string.sub(txt, 1, bitsize) table.insert(bits, bit) txt = string.sub(txt, bitsize + 1) if string.len(txt) <= bitsize then local bit = string.sub(txt, 1, bitsize) table.insert(bits, bit) end end end [/lua] That fixed the cutting off part when receiving the string... but still for some reason the MOTD Derma doesn't want to want to put the string in... It cuts out after like the 1100 - 1200th character. :S [editline]4th May 2012[/editline] Does Derma have a limit on characters allowed in each "DLabel" ?
SizeToContents() after setting the text.
I already have that. [editline]5th May 2012[/editline] I also had it print on the client side right before it was put into the Derma and it prints the entire string.
I guess I should give more info.. It cuts out mid-word at the beginning of the paragraph.. for example: Blah blah blah blah blah blah why doesn't this code work properly? It really doesn't make much sense bec Is there a limit to how many characters can be in a DLabel? :S I do have SizeToContents()
Bamp
It's been quite awhile but I still need help on this... Just to recap, my problem is that the DLabel seems to cut out mid sentence like this: [code] Blah blah blah blah blah blah why doesn't this code work properly? It really doesn't make much sense bec [/code] This is somewhere after 1100 characters... Is this because DLabels have a limit as to how many characters can be put into a DLabel?
What about using the resource.AddFile idea with a naming scheme? for example you could use a special prefix like myMOTD then either tack on the date myMOTD5-16-12.txt or a random string myMOTDyikl.txt, myMOTDmwlo.txt, etc. then after the client connects and downloads the current one go delete the old files that fit the pattern. myMOTD????.txt all these files would be in the data directory.
That's not the problem. I worked out how to give the clients the data. The client does download it all and stitch it all back up properly, it just doesn't show all of it into the DLabel...
[QUOTE=InfernalCookie;35991534]That's not the problem. I worked out how to give the clients the data. The client does download it all and stitch it all back up properly, it just doesn't show all of it into the DLabel...[/QUOTE] yea, I kind didn't read all the posts, but when i figured out you'd got it working I thought i'd post anyway just to get the option out there. As far as the DLabel issue when I ran into this I ended up doing a DLabel per line, and I just broke the lines up by hand, however it should be easy to write a function to split any text up properly. This is the code for the instructions on a battleship gamemode I was making. in cl_init.lua [lua] --Instruction definition local InstructText = { "Welcome to gBattleship", " ", "This is a remake of the classic board game, where 2 people launch blind shots on a grid to try and sink their opponents ships, but.....", " ", "In this version you can play with 2, 4, or more people", "First things first, ship placement:", "To place your ships, right click to rotate the ship 90 degrees, and the left click to place the ship.", "If you can not place a ship(part is off the grid, or over another ship) it will briefly turn red.", "After you place your ship press F4 when you are ready to participate in the game, after 2 people have pressed", "F4, the remaining players will have " .. GM.preStartTime .. " seconds before the round starts to enroll by", "pressing F4.", "During play if you wish to see the top view of your ships again, press F3.", " ", "After the round starts a random player is selected to go first, at the beginning of your turn you well be presented with", "an attack selection dialog, it has the players in the round listed and how many ships they have left. Select a player and", "click the attack button.", " ", "Next on the wall of your control room you will see a large blue grid, this is the control grid. When it's your turn click", "on a square will cause a missile to launch at the selected player. If it hits, the square will turn red(with an X), if it", "hits the square will turn a white version of the blue square.", " ", "Play continues until there is only 1 player left, that player wins. The game then resets and you start all over again.", " ", "Special Weapons can be obtained after destroy an enemy ship, weapons you get will be based on your rank.", "Rank 1-5 = No Specials, Rank 5-10 = Basics 3 Shot Missile, Rank 10-15 = 9 Shot Missile, Rank 15+ = 25 Shot Missile", "Missile can be configured by looking at them in your control room and pressing F2", " ", "Press F1 at any time to redisplay this message.", " ", "Have Fun!" } --This is the function that get's call to display the message. local function showIntructions(msgData) showingInst = true local dInst = vgui.Create("DFrame") dInst:ShowCloseButton(false) dInst:SetSize(ScrW() - (ScrW() / 8), ScrH() - (ScrH() / 8)) dInst.alpha = 80 dInst.Paint = PaintOverride dInst:SetDeleteOnClose(true) dInst:SetVisible(true) dInst:SetTitle("How To Play") dInst.DoClick = function() dInst:Close() showingInst = false end local txtColor = Color(255,255,255,255) local txtBlurColor = Color(32,32,32,196) local maxX = 0 local posY = 25 surface.SetFont("InstructsBlur") local txtW, txtH = surface.GetTextSize("W") for k, txt in pairs(InstructText) do local dInstTextBlur = vgui.Create("DLabel") dInstTextBlur:SetParent(dInst) dInstTextBlur:SetPos(10,posY) dInstTextBlur:SetColor(txtBlurColor) dInstTextBlur:SetFont("InstructsBlur") dInstTextBlur:SetText(txt) dInstTextBlur:SizeToContents() local dInstText = vgui.Create("DLabel") dInstText:SetParent(dInst) dInstText:SetPos(10,posY) dInstText:SetColor(txtColor) dInstText:SetFont("Instructs") dInstText:SetText(txt) dInstText:SizeToContents() dInstText.DoClick = function() dInst:Close() showingInst = false end if maxX < dInstText:GetWide() then maxX = dInstText:GetWide() end posY = posY + dInstText:GetTall() + 2 end dInst:SetSize(maxX + 20, posY + 25) dInst:Center() local dCloseBut = vgui.Create("DButton") dCloseBut:SetParent(dInst) dCloseBut:Center() local tX, tY = dCloseBut:GetPos() dCloseBut:SetPos(tX, (posY)) dCloseBut:SetText("Close") dCloseBut.DoClick = function() dInst:Close() showingInst = false end dInst:MakePopup() end usermessage.Hook("show_instructions", showIntructions) [/lua] hope this helps. [editline]17th May 2012[/editline] and this is what that looked like. [t]http://cloud.steampowered.com/ugc/578925859418855004/33506763FF1D5BEDE3B8F0DDE1E3C8F2A47BFB1C/[/t]
Alright, I'll just split it all up by lines, thanks.
Sorry, you need to Log In to post a reply to this thread.