Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   specific adding in a text file (https://forums.graalonline.com/forums/showthread.php?t=70685)

Chompy 12-10-2006 02:55 PM

specific adding in a text file
 
well, as the title says, I'm trying to change something inside a text file (.arc)

my arc files are like this:

HTML Code:

arcnames=
folders=
amount=
account=

Now, all the weapons of the player is stored inside this arc file, into arcnames.
I usually have to do it manually, but, I haven't found a method to edit one member of the file, I made a thread about this, but didn't get what I really wanted (I got confused, in a other way), I got told I could use obj.add();
but how do I use it with loadvars and savelines and such?

I just want to add a string to arcnames, without rewriting the whole script with savelines.. so..

any thoughts?

contiga 12-10-2006 03:44 PM

PHP Code:

public function addArcarcname) {
  
obj = new TStaticVar();
  
obj.loadVars"bladiebla/blabla/file.arc");
  
obj.arcnames.addarcname); // mess a bitwith this ofcourse
  
obj.account player.account;
  
obj.saveVars"bladiebla/blabla/file.arc"0);


Then make sure the player is joined to this, so put it in a joined class or so..
And do player.addArc( arcname); (eventually add an ammount param)

Chompy 12-10-2006 04:49 PM

Quote:

Originally Posted by contiga (Post 1251984)
PHP Code:

public function addArcarcname) {
  
obj = new TStaticVar();
  
obj.loadVars"bladiebla/blabla/file.arc");
  
obj.arcnames.addarcname); // mess a bitwith this ofcourse
  
obj.account player.account;
  
obj.saveVars"bladiebla/blabla/file.arc"0);


Then make sure the player is joined to this, so put it in a joined class or so..
And do player.addArc( arcname); (eventually add an ammount param)

Thanks, I'll try this :D

Admins 12-10-2006 04:51 PM

Yes right now you have to read and write the whole file if you want to change something in the file. If you just want to append a line then you can use 1 instead of 0 for the second parameter to savelines/savevars/savestring

Chompy 12-10-2006 04:56 PM

Quote:

Originally Posted by Stefan (Post 1251994)
Yes right now you have to read and write the whole file if you want to change something in the file. If you just want to append a line then you can use 1 instead of 0 for the second parameter to savelines/savevars/savestring

hmm, was 0 overwrite, or was 1 that?


btw, obj.remove(obj2) do that also work? (Removing of items :))

contiga 12-10-2006 05:33 PM

Quote:

Originally Posted by Chompy (Post 1251996)
hmm, was 0 overwrite, or was 1 that?


btw, obj.remove(obj2) do that also work? (Removing of items :))

0 = overwrite
1 = create (a) new line(s) (simply a copy of the old stuff, + some added stuff (in this case))
_

obj.remove( obj2) would work, just don't fill in an index number for obj2, but the actual text to remove, and it will search for it's position in the string, and remove it.

Chompy 12-10-2006 06:08 PM

Quote:

Originally Posted by contiga (Post 1252000)
0 = overwrite
1 = create (a) new line(s) (simply a copy of the old stuff, + some added stuff (in this case))
_

obj.remove( obj2) would work, just don't fill in an index number for obj2, but the actual text to remove, and it will search for it's position in the string, and remove it.

Hmm, ok :)

One last question: can I set a member directly? Since when I load a member
by using obj.loadvars() it appears as an array, like if I did echo( arcnames[ 0]) it would return the first member, so.. Can I set it directly?

PHP Code:

object.arcnames0] = "foo"

This is for the ammount stuff, to change an current ammount of an arc

contiga 12-10-2006 07:52 PM

Quote:

Originally Posted by Chompy (Post 1252004)
Hmm, ok :)

One last question: can I set a member directly? Since when I load a member
by using obj.loadvars() it appears as an array, like if I did echo( arcnames[ 0]) it would return the first member, so.. Can I set it directly?

PHP Code:

object.arcnames0] = "foo"

This is for the ammount stuff, to change an current ammount of an arc

You could make a function for it.. player.changeArc( arc, positive or negative ammount);

and then:
PHP Code:

public function changeArcarcmod) {
  
obj = new TStaticVar();
  
obj.loadVars"bladiebla/blabla/file.arc");
  
temp.a_index obj.arcnames.indexarc);
  
temp.a_current objtemp.a_index].ammounts;
  
temp.a_new = ( mod.substring01) == "-") ? temp.a_current mod.substring1) : temp.a_current mod;
  
objtemp.a_index].ammounts temp.a_new;
  
obj.saveVars"bladiebla/blabla/file.arc"0);


Oh and add 'sendToRC( "/refreshfilelist");' after every function by the way, so it updates the file browser also.


All times are GMT +2. The time now is 09:24 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.