SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 26/08/2008, 03:29 PM   #11
MadCat
Little Clucker
 
Join Date: Aug 2006
Posts: 2
Reputation: 0
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

OMFG, this is great! DracoBlue, you are the best!
MadCat is offline   Reply With Quote
Old 26/08/2008, 03:35 PM   #12
luxeon
Huge Clucker
 
Join Date: Dec 2007
Posts: 294
Reputation: 0
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

nice,gonna use it
luxeon is offline   Reply With Quote
Old 27/08/2008, 05:06 PM   #13
Antironix
Gangsta
 
Join Date: May 2007
Posts: 702
Reputation: 20
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

I am now trying more then 2 hours to get some thing right .

ATM I have this piece of code:

pawn Code:
GetPlayerName(playerid,player,24);
format(str, sizeof(str), "%s/Health", player);
djSetInt("Accounts.json", str, udb_hash(params));
format(str, sizeof(str), "%s/Money", player);

Now this is working good, it will show this in the file:

Code:
{"Antironix":{"Health":100.000000,"Money":0}}
But how can I make it that it is writing to a new line? Like it should show this:

Code:
{"Antironix":{"Health":100.000000,"Money":0}}
{"Player2":{"Health":100.000000,"Money":0}}
..etc...
Thanks It's just a new kind of code for me.
Antironix is offline   Reply With Quote
Old 27/08/2008, 05:15 PM   #14
DracoBlue
Gangsta
 
Join Date: Apr 2006
Posts: 680
Reputation: 74
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

You are trying already the right thing :). Do not be confused by the way it is displayed!

The problem you are facing is, that the root is always (I do not intend to change that, though) an object (displayed by { ... }) and not an array (displayed by [nobbc][[/nobbc] ... [nobbc]][/nobbc]).

But: what you want to do does not depend on anything like arrays or objects, because it works even better like you already do that with objects and exactly the way you make that :-P!

pawn Code:
djSetInt("Accounts.json", "Draco/Health",100);
djSetInt("Accounts.json", "Draco/Money",10000);
djSetInt("Accounts.json", "Wadabak/Health",30);
djSetInt("Accounts.json", "Wadabak/Money",500);

... the Accounts.json looks (easily) like that:
{"Draco":{"Health":100,"Money":10000},"Wadabak:{"H ealth":30,"Money":500}}

Let's have a close look at this:
{
"Draco":{
"Health":100,
"Money":10000
},
"Wadabak:{
"Health":30,
"Money":500
}
}

So it's already what you wanted to have, just smaller saved (for space/speed reasons).

- Draco
__________________

dcmd 1.0 | dini 1.6 | djson 1.6.2 (The offic. DiniČ) | DMap 0.4 | DModule 0.13 (Dynamic GM/FS) | DUDB 2.4 | DTest 1.2 | Dutils 1.10

[dracoblue's dev-diary] • [php + javascript developer]

DracoBlue is offline   Reply With Quote
Old 27/08/2008, 05:30 PM   #15
Antironix
Gangsta
 
Join Date: May 2007
Posts: 702
Reputation: 20
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

Ah, I got it.

I've did this:
1) Registered my self, it was writen correctly.
2) Changed my name in the file and saved it.
3) Reregistered myself.

But as the changed name of the file hasn't been reloaded in the cache the system didn't knew it and overwrited the previous one.


A question: Is the long delay normal, like ~1-2 seconds with 8 writings?

This is not a problem because I am going to use this only in register/login/disconnect so the player won't notice it during his gameplay.

Also if you don't mind, can I release the register system I am making? Because this may be confusing for new users.

Thanks again

EDIT: I have forgotten one question.

Is it possible to have a better overlooking code, like you just posted at last? (I guess not xD)
Antironix is offline   Reply With Quote
Old 27/08/2008, 05:32 PM   #16
Grove
Huge Clucker
 
Join Date: Jan 2007
Posts: 299
Reputation: 6
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

Omg Nice!
Grove is offline   Reply With Quote
Old 27/08/2008, 05:37 PM   #17
DracoBlue
Gangsta
 
Join Date: Apr 2006
Posts: 680
Reputation: 74
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

Quote:
Originally Posted by Wadabak
I've did this:
1) Registered my self, it was writen correctly.
2) Changed my name in the file and saved it.
3) Reregistered myself.

But as the changed name of the file hasn't been reloaded in the cache the system didn't knew it and overwrited the previous one.
So, if you want to do that, better make it different :-P. Changing names is always hard, if you save the data on that name.

If you want to reload the info, better use DJSON_cache_ReloadFile(filename[]) once or use for example dj(file[],path[],use_cached_value) with use_cached_value = false, this will "force" to load from file always. No caching is used here. Even though I do not suggest that for big files.

Quote:
Originally Posted by Wadabak
A question: Is the long delay normal, like ~1-2 seconds with 8 writings?

This is not a problem because I am going to use this only in register/login/disconnect so the player won't notice it during his gameplay.
So here comes the reason, why you should use djAutocommit and djCommit!

In first place do:
pawn Code:
djAutocommit(false); // after that line, it will only flush the data on djCommit
djSetInt("Accounts.json", "Draco/Health",100);
djSetInt("Accounts.json", "Draco/Money",10000);
... more ...
djSetInt("Accounts.json", "Wadabak/Health",30);
djSetInt("Accounts.json", "Wadabak/Money",500);
djCommit("Accounts.json"); // at this point, it will "flush" all the data into the file!
djAutocommit(true); // after that line, it will automactily flush the data on each call
This is way way faster :). Just for your information, if you do djInt("Accounts.json","Draco/Health") while not having commited the data yet, it will show the current value anyways. This is very helpful if you just want to write some data into the cache and are not sure if you want to keep it :).

Quote:
Originally Posted by Wadabak
Also if you don't mind, can I release the register system I am making? Because this may be confusing for new users.
Of course.

- Draco
__________________

dcmd 1.0 | dini 1.6 | djson 1.6.2 (The offic. DiniČ) | DMap 0.4 | DModule 0.13 (Dynamic GM/FS) | DUDB 2.4 | DTest 1.2 | Dutils 1.10

[dracoblue's dev-diary] • [php + javascript developer]

DracoBlue is offline   Reply With Quote
Old 28/08/2008, 10:27 PM   #18
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,819
Reputation: 650
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

just a question what does "db_query" do ? it looked for me as it would be a standart function because I didnt found any stock public
Nero_3D is offline   Reply With Quote
Old 28/08/2008, 10:38 PM   #19
DracoBlue
Gangsta
 
Join Date: Apr 2006
Posts: 680
Reputation: 74
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

Quote:
Originally Posted by Nero_3D
just a question what does "db_query" do ? it looked for me as it would be a standart function because I didnt found any stock public
db_query can be found in sampdb.inc and is about database queries to the built in sqlite-database.

- Draco
__________________

dcmd 1.0 | dini 1.6 | djson 1.6.2 (The offic. DiniČ) | DMap 0.4 | DModule 0.13 (Dynamic GM/FS) | DUDB 2.4 | DTest 1.2 | Dutils 1.10

[dracoblue's dev-diary] • [php + javascript developer]

DracoBlue is offline   Reply With Quote
Old 29/08/2008, 03:21 AM   #20
JaTochNietDan
High-roller
 
JaTochNietDan's Avatar
 
Join Date: Apr 2007
Location: Republic of Ireland
Posts: 2,502
Reputation: 363
Default Re: DJson 1.2 - Fast/Extensive File Reader/Writer (Official DiniČ)

I'm lovin it.
__________________
Releases:
[Includes]: [jBan] | [jBanLite]
[Plugins]: [FileManager] | [Execute]
[Applications]: [Remote Administrator *NEW] | [Script King] | [RCON GUI]
JaTochNietDan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] [INC] SII 2.0.6 - Fast cache based INI Reader/Writer [DRuG]Slick Includes 95 02/07/2017 04:23 PM
From Dini To DjSon MafiaGuy™ Help Archive 5 27/08/2010 05:39 PM
Create Vehicle from file (Need Very Fast) epranka Help Archive 2 04/06/2010 10:31 AM
FAST READER (INI SYSTEM) MahmutBey Help Archive 2 08/05/2010 08:16 PM
Reading from file works not perfect.. [NOT SOLVED] RyDeR` Help Archive 9 28/02/2010 08:01 AM


All times are GMT. The time now is 04:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.