![]() |
A Question on File-Options - Printable Version +- SphereCommunity (https://forum.spherecommunity.net) +-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d) +--- Forum: Script Help (/Forum-Script-Help) +--- Thread: A Question on File-Options (/Thread-A-Question-on-File-Options) Pages: 1 2 |
A Question on File-Options - Shidhun - 02-12-2013 01:16 AM Hello, maybe someone can help me with this. I have a separate file with many Informations on Items. On every line there is a string that contains several Informations on Items, like ID/Color and so on. So, my Question is. How do i delete a specific fileline in this file. I know how to read every line i want, and how to resolve the informations etc etc. The thing is, in some situations i need to alter a Fileline or to to remove it completely. Is there a way to do it, or do i need to create a new file via writeline, without the string-informations i don't need anymore. An example: I have a Gump that contains the informations to 50 Items. It is easy to do this via Filelines/Readline. Lets say now, that i don't need the Information on Line 47 any more. How do i delete Line 47 without loosing the Informations on the other 49 Lines, or do i need to use a workaround with storing every line in a local, deleting the original file, and than creating a new one without "local 47" RE: A Question on File-Options - Mordaunt - 02-12-2013 01:34 AM Perhaps an example of the file you are talking about would assist in understanding what you need to remove RE: A Question on File-Options - Shidhun - 02-12-2013 01:57 AM Ok lets say i'll try to store many items in a cabinet. [DIALOG d_cabinet] 50,71 //nodispose //noclose File.mode.readflag=1 page 0 resizepic 0 0 2620 300 503 checkertrans 5 5 290 493 resizepic 350 0 2620 300 503 checkertrans 355 5 290 493 dtext 10 25 180 Items : if (<file.fileexist cabinet/cabinet.txt>) <file.open cabinet/cabinet.txt> local.ox=20 local.oy=65 for <file.filelines cabinet/cabinet.txt> call f_cabinet_resolve <FILE.Readline <local._for>> //Buttons button <local.ox> <eval <local.oy> +5> 1209 1210 1 0 <eval <local._for> +1000> //Text-Entries dtext <eval <local.ox> +20> <local.oy> 180 <local.name> local.oy +=20 if <local._for> > 20 local.ox +=100 endif endfor endif FILE.CLOSE [DIALOG d_cabinet BUTTON] On=1001 1050 IF (<FILE.FILEEXIST cabinet/cabinet.txt>) <file.open cabinet/cabinet.txt> call f_cabinet_resolve <FILE.Readline <eval (<ARGN1>-1000)>> //reads lines 1-50 serv.newitem <local.id> new.name=<local.name> new.color=<local.color> new.attr=<local.flags> new.more1=<local.more1> new.bounce <src> ENDIF FILE.CLOSE [Function f_cabinet_resolve] local.name=<argv[0]> local.id=<argv[1]> local.color=<argv[2]> local.flags=<argv[3]> local.more1=<argv[4]> The File cabinet.txt contains informations like : name1,id1,color1,flags1,more1,..... name2,id2,color2,flags2,more2,..... name3,id3,color3,flags3,more3,..... ..... name50,id50,color50,flags50,more50,..... So. i can display every line of the File in my Gump. And i can extract/create each item, if wanted. But the Cabinet is just for storing Items. When you take one out, obviousely it shouldn't "stay" in the Cabinet, so the entry has to be deleted. You may ask, why does he want to use File-Options, when it is much simpler to just use tags on the Cabinet. Well.. it is a RP-Server without a Maximum of items per character. So many characters have thousands of Items (in this case sets of clothing). It is definitely not good to store up to hundreds of tags on a item. The Script is for Item-Reduction without forcing the players to "lose" items. RE: A Question on File-Options - Mordaunt - 02-12-2013 02:04 AM Ok, question: IS this a script you are creating to behave in this manner or is it a script you are editing to remove some ingame item that you no onger wish avaiable? If it is the first my suggestion is scrap it the way you are looking at it, and use lists attached to the cabinet, removing an item from a list causes all remaining items in the list to shuffle to remove any gaps created. Lists must be unique though as they are globally avaiable, however it if you attach it to the UID of the cabinet you will not have a problem. Code: LIST.xxx to show elements in list. Also, can be used like LIST.xxx=value to clear list and add a value RE: A Question on File-Options - Shidhun - 02-12-2013 08:20 PM Thanks Mordaunt, i never thought about Lists before. Everything is working fine now ![]() RE: A Question on File-Options - admin phoenix - 02-14-2013 09:15 PM any chance, to sort this for example, you have in your list {3},{1},{10},{2} and I want this sorted {1},{2},{3},{10} RE: A Question on File-Options - RanXerox - 02-15-2013 05:00 AM Here is a excerpt from my Poker game scripts to sort an array of cards in a list object... I call out to another function called f_Poker_RankCards to decide which is higher or lower... in your case a simple less than or greater than test is probably sufficient: Code: [FUNCTION f_Poker_SortCards] RE: A Question on File-Options - admin phoenix - 02-15-2013 04:37 PM that´s very very nice script. thank. I will test it in the next few day (very very interesting this script). But it would also be fine, if we have a command like list.xxx.asort // sort upward list.xxx.rsort / sort downward RE: A Question on File-Options - Mordaunt - 02-15-2013 11:47 PM I've not done much with it, but I would imagine that if you wrote a script to loop through the list using LIST.xxx.index and had the count run backwards that it would display the list in reverse RE: A Question on File-Options - darksun84 - 02-15-2013 11:51 PM i am wondering if an implementation of quicksort in sphere's language is worth to do ![]() |