The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Question on File-Options
Author Message
Shidhun
Journeyman
*

Posts: 59
Likes Given: 5
Likes Received: 3 in 3 posts
Joined: Jul 2012
Reputation: 1



Post: #1
A Question on File-Options
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"
02-12-2013 01:16 AM
Find all posts by this user Like Post Quote this message in a reply
Mordaunt
Super Moderator
****

Posts: 1,237
Likes Given: 26
Likes Received: 55 in 43 posts
Joined: Mar 2012
Reputation: 35



Post: #2
RE: A Question on File-Options
Perhaps an example of the file you are talking about would assist in understanding what you need to remove

[Image: 2nis46r.jpg]
02-12-2013 01:34 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Shidhun
Journeyman
*

Posts: 59
Likes Given: 5
Likes Received: 3 in 3 posts
Joined: Jul 2012
Reputation: 1



Post: #3
RE: A Question on File-Options
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.
(This post was last modified: 02-12-2013 01:59 AM by Shidhun.)
02-12-2013 01:57 AM
Find all posts by this user Like Post Quote this message in a reply
Mordaunt
Super Moderator
****

Posts: 1,237
Likes Given: 26
Likes Received: 55 in 43 posts
Joined: Mar 2012
Reputation: 35



Post: #4
RE: A Question on File-Options
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
LIST.xxx.ADD to add new element to list, can be number or string
LIST.xxx.CLEAR to clear list
LIST.xxx.index to read/write value on element in list
LIST.xxx.COUNT to get count of elements in list
LIST.xxx.index.REMOVE to remove element at specified index in list
LIST.xxx.index.INSERT to insert element at specified index in list
LIST.xxx.FINDELEM search_value returns index of first found element in list. Search starting from begin
LIST.xxx.index.FINDELEM search_value returns index of first found element in list. Search starting from index
SERV.PRINTLISTS to print all lists and their elements
SERV.CLEARLISTS to clear all lists. If used with mask parameter, then clear all lists, which name countains specified mask

[Image: 2nis46r.jpg]
02-12-2013 02:04 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Shidhun
Journeyman
*

Posts: 59
Likes Given: 5
Likes Received: 3 in 3 posts
Joined: Jul 2012
Reputation: 1



Post: #5
RE: A Question on File-Options
Thanks Mordaunt,

i never thought about Lists before.

Everything is working fine now Smile
02-12-2013 08:20 PM
Find all posts by this user Like Post Quote this message in a reply
admin phoenix
Master
**

Posts: 354
Likes Given: 1
Likes Received: 23 in 13 posts
Joined: Mar 2012
Reputation: 3



Post: #6
RE: A Question on File-Options
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}
02-14-2013 09:15 PM
Find all posts by this user Like Post Quote this message in a reply
RanXerox
Master
**

Posts: 550
Likes Given: 1
Likes Received: 12 in 9 posts
Joined: Dec 2010
Reputation: 19



Post: #7
RE: A Question on File-Options
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]
//"
// Usage: f_Poker_SortCards CardArray
//
// Sorts an existing LIST object named CardArray, which is assumed to contain
// CardSymbols.  The sort order has highest ranked cards (Ace) first (suit is
// ignored.)
//"
IF (<ARGV>==0)
   f_pokerlog 1,"Poker_SortCards: needs a CardArray"
   RETURN 1
ENDIF
LOCAL.Input=<ARGS>
LOCAL.InputSize=<LIST.<LOCAL.Input>.COUNT>
IF (<LOCAL.InputSize> < 2)
   f_pokerlog 1,"Poker_SortCards: CardArray <LOCAL.Input> is too small to sort"
   RETURN 1
ENDIF
//f_pokerlog 1,"Poker_SortCards: Start sorting <LOCAL.Input> (size=<LOCAL.InputSize>)"
LOCAL.Swapped=1
WHILE (<dLOCAL.Swapped>==1)
   LOCAL.Swapped=0
   FOR LoopNumber 1 <EVAL <LOCAL.InputSize>-1>
      IF (<LOCAL.LoopNumber>)
         LOCAL.CardA="<STRSUB 1 2 <LIST.<LOCAL.Input>.<EVAL <LOCAL.LoopNumber>-1>>>"
         LOCAL.CardB="<STRSUB 1 2 <LIST.<LOCAL.Input>.<dLOCAL.LoopNumber>>>"
//         f_pokerlog 2,"Poker_SortCards: ..Loop=<dLOCAL.LoopNumber>: Is <LOCAL.CardA> ranked higher than <LOCAL.CardB>?"
         IF (<f_Poker_RankCards <LOCAL.CardA>,<LOCAL.CardB>>==-1) //CardA ranks lower than CardB
//            f_pokerlog 3,"Poker_SortCards: ....swap them"
            LIST.<LOCAL.Input>.<EVAL <LOCAL.LoopNumber>-1>=<LOCAL.CardB>
            LIST.<LOCAL.Input>.<dLOCAL.LoopNumber>=<LOCAL.CardA>
            LOCAL.Swapped=1
//         ELSE
//            f_pokerlog 3,"Poker_SortCards: ....skipping"
         ENDIF
      ENDIF
   ENDFOR
   LOCAL.InputSize=<EVAL <LOCAL.InputSize>-1>
ENDWHILE
//f_pokerlog 1,"Poker_SortCards: Sorting Completed"
02-15-2013 05:00 AM
Find all posts by this user Like Post Quote this message in a reply
admin phoenix
Master
**

Posts: 354
Likes Given: 1
Likes Received: 23 in 13 posts
Joined: Mar 2012
Reputation: 3



Post: #8
RE: A Question on File-Options
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
02-15-2013 04:37 PM
Find all posts by this user Like Post Quote this message in a reply
Mordaunt
Super Moderator
****

Posts: 1,237
Likes Given: 26
Likes Received: 55 in 43 posts
Joined: Mar 2012
Reputation: 35



Post: #9
RE: A Question on File-Options
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

[Image: 2nis46r.jpg]
02-15-2013 11:47 PM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
darksun84
Sir Spamalot
****

Posts: 1,687
Likes Given: 245
Likes Received: 162 in 151 posts
Joined: Mar 2012
Reputation: 35



Post: #10
RE: A Question on File-Options
i am wondering if an implementation of quicksort in sphere's language is worth to do Shock
02-15-2013 11:51 PM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)