PDA

View Full Version : [Include] DJson 1.6.2 - Fast/Extensive File Reader/Writer (Official Dini²) (Works in FS)


Pages : [1] 2

DracoBlue
25/08/2008, 12:21 PM
DJson
Version 1.6.2 (Changelog (http://dev.dracoblue.net/index.php/DJson/Changelog))

Dini (http://forum.sa-mp.com/index.php?topic=981.0) got downloaded nearly 15.000 already! Big thank you to everyone trusting in it!

Today I want to publish the next level of saving data to files. DJson is the library to save more then just little text-strings to files. It contains a cache to make your advanced gamemodes faster, it contains objects/arrays and a transaction based environment (djAutocommit) to override all speed/space/structure limits of dini. With approx 1.700 lines of code its, way bigger then the 250loc dini :).

And last but not least: Its published under MIT-License. Use it, love it, hack it, sell it!

I really hope and want to keep what most of you connect with my releases: reliable code! This library walked through massive api tests and technical proofs, so it should work as expectd. Please report if you got any issues, so all others have benefit, too!

Download
Latest Version of DJson is 1.6.2 and can be found at the Download-Area (http://dracoblue.net/download/djson-162/51/) of DracoBlue.net (djson_1_6_2.zip (http://dracoblue.net/download-release/68/djson_1_6_2.zip)).

Why Djson?

Fast: DJson uses a database for caching purpose. So you can easily access the whole filesystem, read/write data, because they are already in the memory! Take a look at djAutocommit (http://dev.dracoblue.net/index.php/DJson#djAutocommit) if you want to use the full power!
Secure: You can use anything but "/" parts of the keys, so save whatever you want - no incompatibilites here! Files are saved, as soon as the whole data is in the cache, so you won't lose any data, even if you turn of the computer while adding data! (Att: This does not count for the final commit, but it's pretty fast, though :-) )
Unlimited (512 chars) structured items for paths and content: In djson you can use pathes, like this/is/a/very/long/......./path/up/to/512/characters. In djson you can use so much content as you want, just properly update the DJSON_MAX_STRING, if 512 is still not enough! And of course this limit counts for every single item, so player/vehicle can have unlimited amount of subitems, with again 512 characters!
DJSON_MAX_STRING should be at least 170 + maxfilenamelength + maxkeylength + maxvaluelength

Files: A reason why to use djson is of course, that the data is saved to files! Since djson uses the JSON-standard, you may use JavaScript, PHP, Flash, Java, ... and so on, to read the data!
Arrays/Objects: In DJson you can use objects (hashtables) and arrays (lists) with values, which can be nested as deep as you want. The arrays have some sweet extra functionality, like for example the djCount (http://dev.dracoblue.net/index.php/DJson#djCount) and the djAppend (http://Compatible: Since JSON is a standard, you may use (edit/read) the produced files with PHP/Flash/JavaScript/Java/C# and create for example an online map (see [u]dmap (http://forum.sa-mp.com/index.php?topic=71230.0)), with nearly no effort!


References
- Official DJson-Page (http://dev.dracoblue.net/index.php/DJson)
- Examples (http://dev.dracoblue.net/index.php/DJson#Example)
- Function List (http://dev.dracoblue.net/index.php/DJson#Functions)
- Tweaking DJson (http://dev.dracoblue.net/index.php/DJson/Tweaking)
- DJson (http://dracoblue.net/c/djson/)-Blog in my DevDiary (http://dracoblue.net/dev/)

Tutorials
- Register/Login System Using DJson (http://forum.sa-mp.com/index.php?topic=101405.0)
- Why not use ONE big file for all user data (http://forum.sa-mp.com/index.php?topic=101405.msg636899#msg636899)

Known Issues
- none

Usage
I added a small test-script, called stats.pwn to the release, which counts server restarts and player-connect/deaths.

And since I know, most of you guys are too lazy to read the entire API-Documentation at http://dracoblue.net/djson , here comes a quick and dirty script:
Includes!
#include <a_samp>
#include <djson>
main() {
}

Register the callbacks:

public OnGameModeInit() {
djson_GameModeInit(); // <-- this must be called _before_ you can use any djson function!!

djSetInt("stats.json","server/started",djInt("stats.json","server/started")+1);

printf("Server starts: %d",djInt("stats.json","server/started"));

SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}

public OnGameModeExit() {
djson_GameModeExit(); // <-- when you exit the gamemode, after that you can't run any djson function anymore!
return 1;
}

And now some counting:
public OnPlayerRequestClass(playerid, classid) {
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}

public OnPlayerConnect(playerid) {
djSetInt("stats.json","players/connected",djInt("stats.json","players/connected")+1);
return 1;
}

public OnPlayerSpawn(playerid) {
djSetInt("stats.json","players/spawned",djInt("stats.json","players/spawned")+1);
return 1;
}

public OnPlayerDeath(playerid, killerid, reason) {
djSetInt("stats.json","players/died",djInt("stats.json","players/died")+1);
return 1;
}

Have fun coding,
Jan (DracoBlue)

Antironix
25/08/2008, 12:30 PM
Nice one DracoBlue, especially the counting!
is going to convert my codes :)

Xalphox
25/08/2008, 12:37 PM
Oh shit.

MaTrIx4057
25/08/2008, 01:12 PM
Awesome!!

Eyzi
25/08/2008, 01:21 PM
well done

Ycto
25/08/2008, 01:39 PM
Another nice release Draco! Thanks =)

DracoBlue
25/08/2008, 06:24 PM
Glad if you like it.

I am currently working on a (free) web-based-auto-updating map using that as data-source.

[edit] DJson 1.1 released!
* fixed bug in djSet if setting Array-Elements with children
* added djCreateFile
* added djRemoveFile

Djson 1.2 released!
* fixed crash in djUnset, when unsetting the last array element.

- Draco

Antironix
26/08/2008, 11:15 AM
Damn, this is nice. I've just had a better look at it, now I can have all accounts in just one file!

Question: Is it possible to delete 1 string of a line? I'll give you an example.

"vehicles":["PCJ","Cheetah","Banshee"],

Like deleting 'Cheetah' of that vehicles line so it would become this:

"vehicles":["PCJ","Banshee"],


Thanks.

DracoBlue
26/08/2008, 12:23 PM
Damn, this is nice. I've just had a better look at it, now I can have all accounts in just one file!

Question: Is it possible to delete 1 string of a line? I'll give you an example.

"vehicles":["PCJ","Cheetah","Banshee"],

Like deleting 'Cheetah' of that vehicles line so it would become this:

"vehicles":["PCJ","Banshee"],


Thanks.

yes. djUnset("filename","vehicles/1"); // to delete the 2nd item.

- Draco

Antironix
26/08/2008, 12:34 PM
cool, great! Way better as dini :)

MadCat
26/08/2008, 03:29 PM
OMFG, this is great! DracoBlue, you are the best!

luxeon
26/08/2008, 03:35 PM
nice,gonna use it

Antironix
27/08/2008, 05:06 PM
I am now trying more then 2 hours to get some thing right ;).

ATM I have this piece of 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:


{"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:


{"Antironix":{"Health":100.000000,"Money":0}}
{"Player2":{"Health":100.000000,"Money":0}}
..etc...


Thanks ;) It's just a new kind of code for me.

DracoBlue
27/08/2008, 05:15 PM
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 [ ... ]).

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!

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:{"Health":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

Antironix
27/08/2008, 05:30 PM
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)

Grove
27/08/2008, 05:32 PM
Omg Nice!

DracoBlue
27/08/2008, 05:37 PM
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.

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 (http://dev.dracoblue.net/index.php/DJson#djAutocommit) and djCommit (http://dev.dracoblue.net/index.php/DJson#djCommit)!

In first place do:
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 :).

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

Nero_3D
28/08/2008, 10:27 PM
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

DracoBlue
28/08/2008, 10:38 PM
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

JaTochNietDan
29/08/2008, 03:21 AM
I'm lovin it.

sebihunter
29/08/2008, 02:31 PM
whow, that´s nice

Thanks Draco, gonna change everything from dini to DJson now :P

Antironix
29/08/2008, 03:32 PM
I have tried turning the Autocommit of at the beginning of all the data writing, then I commited the file and at the end I turned Autocommit on again.
The time that it takes is still around 2-5 seconds.

And I've maybe found a bug. When I registered directly after a gmx, it didn't stored all the data that I was going to save, it only saved 2 of the 7 savings to the file.

Here is my code:


djAutocommit(false);
format(str, sizeof(str), "%s/Password", player);
djSetInt("Accounts.json", str, udb_hash(params));
format(str, sizeof(str), "%s/Money", player);
djSetInt("Accounts.json", str, GetPlayerMoney(playerid));
format(str, sizeof(str), "%s/Score", player);
djSetInt("Accounts.json", str, GetPlayerScore(playerid));
format(str, sizeof(str), "%s/Health", player);
GetPlayerHealth(playerid, pHealth);
djSetFloat("Accounts.json", str, pHealth);
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
format(str, sizeof(str), "%s/X", player);
djSetFloat("Accounts.json", str, Pos[0]);
format(str, sizeof(str), "%s/Y", player);
djSetFloat("Accounts.json", str, Pos[1]);
format(str, sizeof(str), "%s/Z", player);
djSetFloat("Accounts.json", str, Pos[2]);
djCommit("Accounts.json");
djAutocommit(true);


The variables player and params have been defined already.

Thanks

DracoBlue
29/08/2008, 04:49 PM
I have tried turning the Autocommit of at the beginning of all the data writing, then I commited the file and at the end I turned Autocommit on again.
The time that it takes is still around 2-5 seconds.

The startup usually takes up to 3 or 4 seconds, due to the fact that the sqlite database is slow at startup, which djson uses as cache. Do you mean that?



And I've maybe found a bug. When I registered directly after a gmx, it didn't stored all the data that I was going to save, it only saved 2 of the 7 savings to the file.

Here is my code:


djAutocommit(false);
format(str, sizeof(str), "%s/Password", player);
djSetInt("Accounts.json", str, udb_hash(params));
format(str, sizeof(str), "%s/Money", player);
djSetInt("Accounts.json", str, GetPlayerMoney(playerid));
format(str, sizeof(str), "%s/Score", player);
djSetInt("Accounts.json", str, GetPlayerScore(playerid));
format(str, sizeof(str), "%s/Health", player);
GetPlayerHealth(playerid, pHealth);
djSetFloat("Accounts.json", str, pHealth);
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
format(str, sizeof(str), "%s/X", player);
djSetFloat("Accounts.json", str, Pos[0]);
format(str, sizeof(str), "%s/Y", player);
djSetFloat("Accounts.json", str, Pos[1]);
format(str, sizeof(str), "%s/Z", player);
djSetFloat("Accounts.json", str, Pos[2]);
djCommit("Accounts.json");
djAutocommit(true);


The variables player and params have been defined already.

Can you please provide an example for that? What exactly is not saved? The issue is, that the file needs to be loaded to cache first. So, directly _set_ without _get_ before, won't work like expected. I'll make a fix for that on 1.3 release.

- Draco

Antironix
29/08/2008, 06:21 PM
The startup usually takes up to 3 or 4 seconds, due to the fact that the sqlite database is slow at startup, which djson uses as cache. Do you mean that?

That's not the issue. I've restarted the GM, then I've waited arround 10-15 seconds. I've used the command ~5 seconds later, the SendClientMessage will show. I've putted that sendclientmessage before djCommit("Accounts.json");.


The second thing.
When I have used the command after the gmx, it did fully saved. But then I did gmx again, it only saved 2 items.

It should look like this:

{"Antironix":{"Health":100.000000,"Money":0,"Password":256115588,"Score":0,"X":135.146362,"Y":-67.085334,"Z":1.578125}}


But sometimes it will show this:

{"Antironix":{"Health":100.000000,"Z":-42.978889}}

I'ts like 50% it will show the first one and 50% that it will show the second one.

Also if it will show the second one, it is ALWAYS showing 'Health' and 'Z', so the first and the last saving. And it is still during ~5 seconds when the SendClientMessage is showing.

Thanks.

DracoBlue
31/08/2008, 04:55 PM
Thanks to Wadabak for reporting 1 issue, which is fixed in djson 1.3.

Released Version 1.3 (2008/08/31)
* fixed bug with arrays in djUnset (http://dev.dracoblue.net/index.php/DJson#djUnset)
* fixed dj(Int (http://dev.dracoblue.net/index.php/DJson#djSetInt)/Float (http://dev.dracoblue.net/index.php/DJson#djSetFloat))Set (http://dev.dracoblue.net/index.php/DJson#djSet)-issue, if file hasn't been loaded yet (reported by Wadabak)
* using streamwriter for any commiting -> faster saving
* added djRevert (http://dev.dracoblue.net/index.php/DJson#djRevert)

Please update asap if you are using djUnset or dmap (0.2 released, too!!) :).

- Draco

Antironix
31/08/2008, 05:03 PM
What issue did you fixed? As I still have the bug that it is loading slow and that it is sometimes saving 2 things instead of all 7 things.

DracoBlue
31/08/2008, 05:12 PM
... sometimes saving 2 things instead of all 7 things.
Really? This should be fixed with djson 1.3. Can you give me a case when that happens.

- Draco

Antironix
31/08/2008, 05:20 PM
I'll say it in steps.

1) I did gmx.
2) I've just waited arround 10 seconds.
3) Then I used the command that is writing everything.
4) It will take up to 5 seconds that I will get the message that the command has ended.
5) I only see the first and the second writed value.

Also:
1) I am using the same name so it is overwriting each time the whole file. (I have only 1 name in here, so I can say the whole file :) )
2) I didn't spawned, I am on class selection.(If this does matter).


Thanks, Antironix

DracoBlue
31/08/2008, 05:40 PM
I'll say it in steps.

1) I did gmx.
2) I've just waited arround 10 seconds.
3) Then I used the command that is writing everything.
4) It will take up to 5 seconds that I will get the message that the command has ended.
5) I only see the first and the second writed value.

Also:
1) I am using the same name so it is overwriting each time the whole file. (I have only 1 name in here, so I can say the whole file :) )
2) I didn't spawned, I am on class selection.(If this does matter).

Thanks, Antironix
What happens if you put in _OnGameModeInit a djRevert (http://dev.dracoblue.net/index.php/DJson#djRevert)("Accounts.json"); ?

- Draco

Antironix
31/08/2008, 06:04 PM
The same issue again.

Also where could I put a SendClientMessage in your include to let me know when the sql database has been loaded, so I can check if I am not writing to early.

EDIT: When the problem occurs, the delay of the writing has been increased to arround 5 seconds, when it normal is arround 2 seconds.

DracoBlue
31/08/2008, 06:08 PM
Just to be sure, all you do on your command is:
djAutocommit(false);
format(str, sizeof(str), "%s/Password", player);
djSetInt("Accounts.json", str, udb_hash(params));
format(str, sizeof(str), "%s/Money", player);
djSetInt("Accounts.json", str, GetPlayerMoney(playerid));
format(str, sizeof(str), "%s/Score", player);
djSetInt("Accounts.json", str, GetPlayerScore(playerid));
format(str, sizeof(str), "%s/Health", player);
GetPlayerHealth(playerid, pHealth);
djSetFloat("Accounts.json", str, pHealth);
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
format(str, sizeof(str), "%s/X", player);
djSetFloat("Accounts.json", str, Pos[0]);
format(str, sizeof(str), "%s/Y", player);
djSetFloat("Accounts.json", str, Pos[1]);
format(str, sizeof(str), "%s/Z", player);
djSetFloat("Accounts.json", str, Pos[2]);
djCommit("Accounts.json");
djAutocommit(true);
?

If that's so, I'll try to make the same thing.

You can put a SendClientMessage somewhere at the end of DJSON_cache_ReloadFile and it will be called, as soon as the database thinks that your file is loaded.

Also:
printf("DJSON: #%d %s",DJSON_LastErrorCode,DJSON_LastError);
after a djson call, should give you every error, which may occur, when executing an djson statement.

- Draco

Tez2k7
31/08/2008, 06:17 PM
Very Nice! ;)

Antironix
31/08/2008, 06:17 PM
Yeah, appart from some GetPlayerName functions.

O.. great. I have figured out that sometimes the file reloading is taking more than 5 seconds, sometimes even 20 seconds.

I've solved the problem now.

DracoBlue
31/08/2008, 06:43 PM
I've solved the problem now.
Eh, how?

- Draco

Antironix
31/08/2008, 06:44 PM
By just waiting till the reloadfile function has been fully loaded :) Sometimes it is taking way longer then other times.

DracoBlue
31/08/2008, 06:47 PM
I have figured out that sometimes the file reloading is taking more than 5 seconds, sometimes even 20 seconds.

This should definately only happen while the djson_GameModeInit is executed, or loading the file for the first time (or if it's a big one). I am very sorry for that, but the sqlite database is quite slow, when it comes to writing (which happens when data is read for the first time), so the first dj-command will be slow, all following "get"-commands will be lightning faster :-).

- Draco

Antironix
31/08/2008, 06:49 PM
Ah oke, I will put the message infront of the writing, so the user won't notice it ;)

I'll let you know if I find some more bugs.

DracoBlue
17/09/2008, 06:58 AM
Hey,

today I release DJson 1.4.

This is a speed update. I changed the cache-table from file to memory and removed the journal option, so here is what the speedresults are (performance testcases):
djson 1.3: 10 seconds
djson 1.4: 0.2 seconds

So update your djson as soon as you can :).

- Draco

thaigta
17/09/2008, 03:17 PM
nice job

Finn
17/09/2008, 06:01 PM
Do I have to update the file system somehow every time I restart my game mode? Cuz it seems like all values and shit are 0 or empty when I try to read them after the restart.

The system works perfectly until I restart the game mode, what's wrong?

DracoBlue
17/09/2008, 06:38 PM
Do I have to update the file system somehow every time I restart my game mode? Cuz it seems like all values and shit are 0 or empty when I try to read them after the restart.

The system works perfectly until I restart the game mode, what's wrong?

Using gmx?

Just to be sure: you are not accidently calling djAutocommit(false) somewhere, without djCommit + djAutocommit(true) in the end?

Could anyone else also reporduce this issue? I haven't tested that, though.

- Draco

Finn
17/09/2008, 06:41 PM
Nope, I ain't using djAutocommit at all.

Edit: System works perfectly, and it really is pretty fast, until I restart the server (with gmx or without - it's the same). After restart it looks like I can't read the files correctly or something.

DracoBlue
17/09/2008, 07:04 PM
Nope, I ain't using djAutocommit at all.

Edit: System works perfectly, and it really is pretty fast, until I restart the server (with gmx or without - it's the same). After restart it looks like I can't read the files correctly or something.

Is the file (*.json) correct?
Do you maybe use djCreateFile again at startup?
Can you backup it before restart and check it after restart again?

Maybe even send the testcase to jans / dracoblue.de?

- Draco

Bpb
18/09/2008, 08:49 AM
if the server crashed, I will lose all unsaved data? :s

DracoBlue
18/09/2008, 08:59 AM
if the server crashed, I will lose all unsaved data? :s

Actually all data automaticly saves (if you do not disable the "auto save" with djAutocommit(false)).

If you have any further questions, ask :).

- Draco

Finn
18/09/2008, 01:29 PM
Still this same shitty bug. I tried another way of making my register system and still not working after I close my gamemode.

Have you even tested this shit out? Try to make some bigger script with this DJSON and you'll notice that it doesn't work after restart. It works great with small files, but if the file is huge with a lot of different paths, it cannot read it.

Still the same question: Do I need to update the system somehow after every restart or something?

The system is bugged as fuck, or my script has got a bug in it. I've tried 2 times to make it work, both times I failed.

Has anyone else these same problems as I do? Does anyone actually use this system or am I the only one? lol

Edit: Sorry my language, but I've been stuck in this same problem for 2 days now and I want to keep going with my script so I get it done some day.

DINI is too slow for my script, but this seems like it's fast enough. Too bad it doesn't work after I close my gamemode. Can somebody make a working script, so I can see how to read, write and handle the files correctly with this system?

Nero_3D
18/09/2008, 01:52 PM
I dont know because I never tested djson - because I dont rly script anything for myself just help other people here XD
If you dont get djson to work I would prefer to the normal file functions because dini is maybe a nice script but how everyone know each function open and close the file again XD if you use the file functions by yourself you just need to open it once and close it once

DracoBlue
18/09/2008, 02:57 PM
Still this same shitty bug. I tried another way of making my register system and still not working after I close my gamemode.

Have you even tested this shit out? Try to make some bigger script with this DJSON and you'll notice that it doesn't work after restart. It works great with small files, but if the file is huge with a lot of different paths, it cannot read it.

Still the same question: Do I need to update the system somehow after every restart or something?

The system is bugged as fuck, or my script has got a bug in it. I've tried 2 times to make it work, both times I failed.

Has anyone else these same problems as I do? Does anyone actually use this system or am I the only one? lol

I use it with dmap and lots of data/writing and reading. Please try to answer my questions :).

Before you restart, is the *.djson file correct? Maybe post the contents!
After you restart, is the *.djson file correct?
Maybe send me the source code at my email adress jans / dracoblue.de, I'll keep privacy about whatever it is.

Edit: Sorry my language, but I've been stuck in this same problem for 2 days now and I want to keep going with my script so I get it done some day.
I know how annoying this is :).

- Draco

Finn
18/09/2008, 03:26 PM
I made an example script for you. I made it fast so it may have some stupid mistakes.

Command:

public OnPlayerCommandText(playerid, cmdtext[])
{
new string[256];
if(strcmp("/test", cmdtext, true, 10) == 0)
{
for(new idx = 0; idx < 100; idx++)
{
format(string,sizeof(string),"test%d", idx);
if(!djIsSet("test.json",string))
{
djAutocommit(false);
format(string,sizeof(string),"test%d/test1", idx);
djSetFloat("test.json", string, 1.1);
format(string,sizeof(string),"test%d/test2", idx);
djSet("test.json",string, "BlahBlahSomething");
format(string,sizeof(string),"test%d/test3", idx);
djSetInt("test.json",string, 1);
djCommit("test.json");
djAutocommit(true);
return 1;
}
}
return 1;
}
return 0;
}


GameModeInIt & Exit

public OnGameModeInit()
{
if(!fexist("test.json"))
{
djCreateFile("test.json");
}
LoadStuff();
djson_GameModeInit();
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}

public OnGameModeExit()
{
djson_GameModeExit();
return 1;
}


LoadStuff Remember to forward

public LoadStuff()
{
new string[256];
for(new idx = 0; idx < 100; idx++)
{
format(string,sizeof(string),"test%d", idx);
if(djIsSet("test.json",string))
{
printf("TEST: %d. test1: %f, test2: %s, test3:%d.", idx, djFloat("test.json", "test%d/test1"), dj("test.json", "test%d/test2"), djInt("test.json", "test%d/test3"));
}
}
return 1;
}


How to see the bug:
- Run the script (lol)
- Get in game.
- Type /test a few times, so it'll set the file.
- Get out of the server.
- Shut down the server.
- Start the server again and look in the console. It should send "TEST: %d. test1: %f, test2: %s, test3:%d." if it could read the file, but it can't so it doesn't send it. What's wrong?

Question:
Am I doing something wrong, or is this a bug?

DracoBlue
18/09/2008, 03:48 PM
1st Misstake Important! <--- this one!! :)
This, won't work:
LoadStuff();
djson_GameModeInit();
This does:
djson_GameModeInit();
LoadStuff();

2nd Misstake in LoadStuff:
djFloat("test.json", "test%d/test1")
djFloat("test.json", "test%d/test2")
djFloat("test.json", "test%d/test3")

This won't work. As you don't have formated this string correctly, and %d works only in format and not in djFloat :).

- Draco

Finn
18/09/2008, 03:55 PM
So make it:

public LoadStuff()
{
new string[256];
for(new idx = 0; idx < 100; idx++)
{
format(string,sizeof(string),"test%d", idx);
if(djIsSet("test.json",string))
{
format(string,sizeof(string),"test%d/test1", idx);
printf("TEST: %d. test1: %f.", idx, djFloat("test.json", string));
}
}
return 1;
}

DracoBlue
18/09/2008, 03:57 PM
1st Misstake Important! <--- this one!! :)
This, won't work:
LoadStuff();
djson_GameModeInit();
This does:
djson_GameModeInit();
LoadStuff();

Checked that part? Since it is the real issue here! :)

- Draco

Finn
18/09/2008, 04:02 PM
Oooh that's why.

DracoBlue
18/09/2008, 04:05 PM
Oooh that's why.

Of course, djson_GameModeInit must be called before any djson related stuff.

So we got the evil part of your code here :). Finally!

[edit] I added this info to the first post example, even though I expected this to be clear :).

- Draco

Finn
18/09/2008, 05:17 PM
Ok, still not working for some reason. I'll just use Dini, because it seems to be the only system that's working correctly.

One thing for you; Can you PLEASE update the dini system a little bit and make it faster as it is pretty slow right now.

:)

DracoBlue
18/09/2008, 07:10 PM
Ok, still not working for some reason. I'll just use Dini, because it seems to be the only system that's working correctly.
Finn, why? :).

Really, djson works pretty good. You just made some very simple misstakes in usage, let me have a look at what you are trying to do, before giving up. So what does not work, what code is involved?

- Draco

Finn
18/09/2008, 07:20 PM
Create file test.json with this info:

{"Test1":0,"Test2":0,"Test3":0,"Test4":0,"Test5":0,"Test6":0,"Test7":0,"Test8":0,"Test9":0,"Test10":0,"Test11":0,"Test12":0,"Test13":0,"Test14":0,"Test15":0,"Test16":0,"Test17":0,"Test18":0,"Test19":0,"Test20":1337}


Read Test20 with this:

printf("Test: %d.", djInt("test.json", "Test20"));


It returns 0, it should return 1337.

DracoBlue
18/09/2008, 08:05 PM
Hello,

as you (surely) haven't noticed, the DJSON_LastError-String was filled with an invalid token in your json file. This was due to an issue with reading only one 0 in the number format of json-files, in my implementation.

It's impossible for me to test every situation, so I am very grateful for you testing and reporting problems with the implementation! Sometimes (like this time) there is really a bug in the implementation! Thank You!

DJson 1.4.1 released.

Changelog:
- fixed issue with single 0 in number format.

- Draco

DracoBlue
20/09/2008, 09:40 AM
DJson 1.5 released

Changelog:
[bug] fixed issue, that files kept open after reading (thanks to xflo for reporting)
[new feature] djStyled(true/false) added, use it to save dj-files with easy human readable indention (thanks to xflo for suggesting)

Also I want to note, that I wrote some articles about djAutocommit, djRevert, djStyled and other ways to tweak djson or get the best out of it :):
• Using djAutocommit (for djson batch operations) (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using_djAutocommit)
• Using djRevert (undo uncommited changes) (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using_djRevert)
• Using/Disable styled output (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using.2FDisable_styled_output)
• Remove djStyled (http://dev.dracoblue.net/index.php/DJson/Tweaking#Remove_djStyled)

Thanks for all the nicely appriciated comments about the speed improvement with djson 1.4 - Glad you like it (now)! :)

Have fun coding,
Draco

Joske_Vermeulen
20/09/2008, 11:22 AM
DracoBlue:


Create file test.json with this info:

{"Test1":0,"Test2":0,"Test3":0,"Test4":0,"Test5":0,"Test6":0,"Test7":0,"Test8":0,"Test9":0,"Test10":0,"Test11":0,"Test12":0,"Test13":0,"Test14":0,"Test15":0,"Test16":0,"Test17":0,"Test18":0,"Test19":0,"Test20":1337}


Read Test20 with this:

printf("Test: %d.", djInt("test.json", "Test20"));


It returns 0, it should return 1337.


I have this same problem, when I set something, it returns correctly but when I gmx, everything returns 0

DracoBlue
20/09/2008, 11:25 AM
Do you do djson_GameModeInit at the beginning?
Do you (accidently) do djCreateFile() at the beginning (what would rewrite the file)?
Do you have djAutocommit(true) or djCommit after setting the value?

What does printf("DJLastError: %s",DJSON_LastError); (right after your dj() which does return 0) print?

- Draco

Tez2k7
20/09/2008, 11:26 AM
Hey,

today I release DJson 1.4.

This is a speed update. I changed the cache-table from file to memory and removed the journal option, so here is what the speedresults are (performance testcases):
djson 1.3: 10 seconds
djson 1.4: 0.2 seconds

So update your djson as soon as you can :).

- Draco


Big improvement. :)

DracoBlue
20/09/2008, 01:03 PM
DJson 1.5.1 released

Changelog:
[bug] fixed issue, that styled files could not be read (thanks xflo for reporting)

Have fun coding,
Draco

Antironix
20/09/2008, 10:30 PM
Draco, that DjStyle function, how much slower will it be? If you are using ~10 functions at once.

DracoBlue
21/09/2008, 07:20 AM
Draco, that djStyled function, how much slower will it be? If you are using ~10 functions at once.

This depends very much on how many items your resulting .djson file has.

Important: This is only for _reading_ and _writing_ the file, as you use the cache:
djAutocommit(false);
... lots of djwork ... // _same_ speed
djCommit(yourfile); // slower, if djstyled is enabled, writes approx. like [ (2 + 2*(avg. depth))*items ] characters extra
djAutocommit(true);

Hint:
- avg. depth is: how/many/slashes/you/use in average :)
- items: every/one, of/those/is, a/item :)

Example: 6000chars, 400 items, avgdepth 2:
So if your compact djson file has like 6000 characters and 400 items and avg. depth of 2, the styled version will need:
6000 + 400*(2 + 2 * 2) characters = 8400 characters. Means, in that case 40% slower write.

Example: 200chars, 10 items, avgdepth 1:
So if your compact djson file has like 200 characters and 10 items and avg. depth of 1, the styled version will need:
200 + 10*(2 + 2 * 1) characters = 240 characters. Means, in that case 20% slower write.

By slower write, remember: we're talking about some ms here.

- Draco

Finn
21/09/2008, 04:49 PM
Okay, now the same problem came up again, files return "0" or "".

LastError gives this error: 'Invalid Token -`! in DJSON_STATE_A'

What did I do wrong this time? lol

DracoBlue
21/09/2008, 05:05 PM
Okay, now the same problem came up again, files return "0" or "".

LastError gives this error: 'Invalid Token -`! in DJSON_STATE_A'

What did I do wrong this time? lol

This means that your .json file is broken.

Actually I noticed that there is a problem with reading negative int/float values, which are saved using djIntSet() or Float.

I am sorry :(.

Investigating now in fixing that, so long use djSet for int's, too.

- Draco

DracoBlue
21/09/2008, 06:04 PM
DJson 1.5.2 released

Important Update! As it fixes issues with loading valid .json files, which contain negative numbers!

Changelog:
- fixed issue, that files with negative numbers could not be read anymore
- added \b and \f escaped to follow the json standard

@Finn this should fix your issue, too.

- Draco

Finn
21/09/2008, 06:50 PM
Still bugged. I think it can't load floats that are negative, like -52.234234something.

As my stats system works great until I save the current position to the userfiles and gmx.

DracoBlue
21/09/2008, 06:54 PM
Still bugged. I think it can't load floats that are negative, like -52.234234something.

As my stats system works great until I save the current position to the userfiles and gmx.

Actually I tested with loading for example: -1.2 (see testcases at the bottom, works like a charm).

This file:
{
"number":{
"eight":-521.123107,
"five":-0.100000,
"four":0.500000,
"one":{
"is":200
},
"seven":-1.000000,
"six":-1.200000,
"three":0,
"two":{
"is":-210
}
}
}
loads perfectly, with all values correct.



If you get a token error, please post the involved .json file.

Big thanks for your patience and support.

- Draco

ledzep
22/09/2008, 02:16 AM
I'm trying to recreate my register function.

The way I have DJson set up at the moment is like this:

File = accounts.json

The first directory/'file path' in the file is the player's name. How would I go about creating a new directory based off a string of the player's name? (like accounts.json/The_Directory_I_Want_To_Add/)

I have something like this:

djSet ("accounts.json","",string,0);

Basically, I'm asking what would I set the "path[]" to?

Kinda hard to explain, sorry if it's unclear.

Finn
22/09/2008, 04:47 AM
Nevermind DracoBlue, it works now. :)

DracoBlue
22/09/2008, 05:03 AM
Hello ledzep,

This:
djSet("accounts.json","",string,0);
is wrong. No matter what you are trying to do. It's wrong :).

When using dj you always use it like that:
djSet(name-of-the-file-on-your-disk,key-of-your-value,content-of-the-value);
optional you can set if you want to use the cache.
djSet(name-of-the-file-on-your-disk,key-of-your-value,content-of-the-value,use-the-cache);

In that case the filename-on-your-disk is always something like accounts.json.

So, you may want one of those two different things:
1. If you want to save the accounts.json at for example "scriptfiles/adminsystem/accounts.json", you may use:
djSet("/adminsystem/accounts.json","config/useanticheat","1");

Hint: Remember that the folder adminsystem has to exist in your scriptfiles folder.

Your accounts.json will look like that then:
{
"config":{
"useanticheat":"1"
}
}

2. If you want use the accounts.json in your normal scriptfiles folder, you may call it like that:

Filecontents afterwards:
djSet("accounts.json","config/useanticheat","1");
{
"config":{
"useanticheat":"1"
}
}

setting different values, would be like that:
djSet("accounts.json","config/useanticheat","1");
djSetInt("accounts.json","DracoBlue/admin",1);
djSetInt("accounts.json","DracoBlue/level",10);

Filecontents afterwards:
{
"config":{
"useanticheat":"1"
}
"DracoBlue":{
"admin":1,
"level":10
}
}

Hope I made clear what the difference between djson-path and path on your harddisk is.

Feel free to ask again, if you have any further questions :).

- Draco


Nevermind DracoBlue, it works now. :). Replaced djFloat with floatstr(dj())

djFloat is just "return floatstr(dj(file,path,use_cached_value));", so this can't be the problem at all :)

ledzep
22/09/2008, 05:57 AM
Well I appreciate the explanation, I did learn a bit more about this great system, but it doens't really answer my question fully.

So the file is "accounts.json".
The directory 'tree' i guess you would call it, goes like this:

accounts.json
{
"player_name":{ // this would actually be the players name, this is the directory I want to create/write
"password":"1"
"etc":"1"
}
}

Since the directory I want to write is at the top of the 'tree', how can I specify it's path?

DracoBlue
22/09/2008, 06:12 AM
Looks good :). So we'll stick to the terminilogy: path = path in the json file.

djson works like that: As soon as you set a value in the path the folder structure is created automaticly.

So if you do:
djSet("accounts.json","DracoBlue/password","gotcha")
it will automacticly create the folder "DracoBlue" in the json file.

If you want to remove a folder or an element, you can use:
djUnset("accounts.json","DracoBlue")
and it will remove even the elements in that folder (in your example password and etc).

Of course the path "DracoBlue" could be even "current/players/dracoblue" or whatever you like.

Hope that helps, quite difficult to explain, since I am using it quite often so I can't see the simple pitfalls :).

- Draco

ledzep
22/09/2008, 06:53 AM
OK well taking that into consideration, I managed to fix my register function! Before it would keep creating accounts with their properties even if they already existed.

This is the code I used


format(string, sizeof(string), "%s", sendername);
djSet ("accounts.json",string,string);


Worked like a charm. I look forward to seeing what this thing can do :P Thanks

ledzep
22/09/2008, 07:04 AM
Maybe one more question about how to get the variables out.


format(tmp2, sizeof(tmp2), "%s/Money", dj("accounts.json",string2));
SetPlayerMoney(playerid,dj("accounts.json",string2));


This doesn't work obviously. How would I get it to set the player's money to the value stored in player_name/Money?

DracoBlue
22/09/2008, 07:19 AM
Maybe one more question about how to get the variables out.


format(tmp2, sizeof(tmp2), "%s/Money", dj("accounts.json",string2));
SetPlayerMoney(playerid,dj("accounts.json",string2));


This doesn't work obviously. How would I get it to set the player's money to the value stored in player_name/Money?

2 things :).

First of all:
As you can see SetPlayerMoney requires a int, so you need to use djInt instead of dj.

Second: What is this supposed to do: format(tmp2, sizeof(tmp2), "%s/Money", dj("accounts.json",string2)); ? :)
You want to format tmp2, so it holds playername/Money, don't you? So use:
format(tmp2, sizeof(tmp2), "%s/Money", PlayerName(playerid));
instead (Assuming you have PlayerName function defined, or know how to get the playername).

This:
format(tmp2, sizeof(tmp2), "%s/Money", PlayerName(playerid));
SetPlayerMoney(playerid,djInt("accounts.json",tmp2));

should do what you want it to do.

- Draco

ledzep
22/09/2008, 02:47 PM
Thanks again,

DracoBlue
22/09/2008, 02:53 PM
Am glad to help. Thanks for using djson, don't hesitate to ask or report issues.

- Draco

david_wood
22/09/2008, 06:37 PM
im trying to make a /register [password]

i want it very very simple ill figure out the rest

ledzep
22/09/2008, 10:13 PM
I've made one that is quite similar to the one found in "The Godfather".

It doesn't use encryption on the password though. Not really a big deal since anybody can go download the godfather and view the "Decrypt" function anyway. You'd have to make your own for it to be secure as far as I know.

Anyway, here it is:

http://pastebin.com/f7b960aa5

DracoBlue
23/09/2008, 07:48 AM
Hello,

I tuned your code a bit. Please see the part with djAutocommit and djCommit, this will make registration faster. Also I added hash-based encryption.

/register+/login #2 :)
http://pastebin.com/f50b36cb7

- Draco

ledzep
23/09/2008, 08:16 AM
stock IsValidName(playerid)
{
if (IsPlayerConnected(playerid))
{
new player[24];
GetPlayerName(playerid,player,24);
for(new n = 0; n < strlen(player); n++)
{
if (player[n] == '_') return 1;
if (player[n] == ']' || player[n] == '[') return 0;
}
}
return 0;
}


the /register uses this as well. Forgot to include it in there, my bad.

ledzep
27/09/2008, 05:09 AM
Edit:

Is there anyway to make arrays of integers rather than strings? I tried to make one contain integers, but it got a bunch of argument mismatches. Or does it really even matter if it's a string or not?

DracoBlue
27/09/2008, 09:38 AM
Is this a djson question or a pawn question. It's possible in both.

- Draco

ledzep
27/09/2008, 06:15 PM
I know how to make arrays of integers/floats, etc... in PAWN, but not in DJson. How do I make an array of integers or floats in DJson?

DracoBlue
28/09/2008, 08:20 AM
Here we go:
- Using djCount, djAppend and djson with arrays(lists) (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using_djCount.2C_djAppend_and_djson_with_ arrays.28lists.29)

As you can see, you can't directly initialize a specific pawn array by using djson, because that would fail the idea behind djson. But you can (that's the purpose) iterate over a specific djson array and access all it's elements step by step, remove items, append items and so on.

Hope it's not too confusing in first place.

Have fun coding,
Draco

Yaheli_Faro
27/10/2008, 07:29 PM
Is this usable in filterscripts too because I just added it into V-Admin 0.5 and now the FS isn't working properly... :s

-Yaheli

DracoBlue
27/10/2008, 07:54 PM
Not direct. You need to apply this changes to the filterscript and update the gamemode, too:
http://pawn.pastebin.com/f7bfea2f5

- Draco

Yaheli_Faro
27/10/2008, 07:57 PM
oh, Will it be made usable in filterscipts without altering anytime soon? :|

DracoBlue
27/10/2008, 08:31 PM
Hopefully with a bugfix in the new samp (bugfix) release. This issue is really related to broken samp core library here, it's pretty impossible for me to change that.

- Draco

DracoBlue
16/01/2009, 07:37 PM
Hi, I don't know if you reply to your PMs but i'm really in need of some help with Djson. I'm currently working on an open-source roleplay gamemode [snip] i'm looking at Djson as an alternative. I can't find much information about it, i need help revamping my register/login system [snip] i don't much understand how Djson saves to the user's file and in what format, does it open/close the file everytime it writes? i think on the wiki page i saw Autocommit enable/disable, what does that do?

how can i read from these files? can i open .json files in notepad?
Hello!

Nice that you noticed that dini is inefficient for that and DJson is actually what you want :).

The expirienced stuff (what you'll need for your script) like djAutocommit is explained at the tweaking djson page (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using_djAutocommit), but let's first manage why/how djson works and get to that stuff later :).

DJson itself is 'just' an interface to the json (http://json.org)-file-format. A json file looks normally like that (you can open that with notepad! - call the file ):
{"name":"draco","cars":[123,234]}
DJson also skips spaces, so the same file could look like that:
{
"name" : "draco"
"cars" : [
123,
234
]
}
(if you want to have such output by djson, check the djStyled (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using.2FDisable_styled_output)-function)

You can now easily read/write that file by using this:
printf("My name is: %s",dj("myfile.json","name"))
// My name is: draco

You can also write:
djSet("myfile.json","name","DRACO")
File will contain:
{"name":"DRACO","cars":[123,234]}

There are of course (like in dini) the following functions, djFloat, djInt, djSetInt and so on - check the djson-page (http://dev.dracoblue.net/index.php/DJson#Functions).

Ready for the next step?

- Draco

Basss
16/01/2009, 07:39 PM
holy shit nice draco :)

Cezar
16/01/2009, 08:00 PM
Hey Draco I wanted to say thanks :D. DJson is epically awesome. I recently created a Player Account Managing include, similar to your DUDB that uses dini. The difference is that this uses your DJson and I noticed that it is a lot faster :D. If you want to see it there's a link in my signature.

Is DJson still being developed? Can we expect more features to come?

DracoBlue
16/01/2009, 08:03 PM
Hey Draco I wanted to say thanks :D. DJson is epically awesome. I recently created a Player Account Managing include, similar to your DUDB that uses dini. The difference is that this uses your DJson and I noticed that it is a lot faster :D. If you want to see it there's a link in my signature.
Thank you! I answer regulary questions about djson via PM, so I thought it was time to post some basics in that topic for general use. I saw your system while searching for djson and looks like you are making good use of djson there! But I am not sure how good it is to do all user accounts in one file if you have a very big server, with lots of accounts, as it can be a speed issue if you do djautocommit then and not write to files every 5 minutes or something like that. (hope you get what I want to say ^^)

Is DJson still being developed? Can we expect more features to come?
Of course. What features do you want to have added? :)

- Draco

pen_theGun
20/01/2009, 02:19 PM
Hey DracoBlue,

today I have noticed, after succesfully deleting my file with djRemoveFile("filename.blabla") Debugging prints: ( File filename.blabla was not accessible, can't remove file! )
Is this fine ?

DracoBlue
20/01/2009, 08:00 PM
Hey DracoBlue,

today I have noticed, after succesfully deleting my file with djRemoveFile("filename.blabla") Debugging prints: ( File filename.blabla was not accessible, can't remove file! )
Is this fine ?

Hello pen_theGun,

thanks for reporting that issue.

Will be fixed with next release, as it is only a display-problem! If you want to fix it on your own, replace line 1696:
if (fremove(file)) {
with:
if (!fremove(file)) {
in your djson.inc.

Thanks again!

- Draco

hamptonin
20/01/2009, 08:10 PM
GOOOOOOOOD

[LDT]LuxurY
27/01/2009, 04:37 AM
:P nice work draco! your codes rules! but why deejay son? ;)

Dinero
27/01/2009, 07:14 AM
Nice! ;)

jwload
30/01/2009, 08:25 PM
I dont know if it's a noob question... but....
I have the players' data, vehicles, houses and properties stored in individual files through the dini...
Then, how i can readapt all my gm for dini²? Because exists several script lines with dini! :s

Sorry bad english :-[

DracoBlue
31/01/2009, 10:37 AM
I dont know if it's a noob question... but....
I have the players' data, vehicles, houses and properties stored in individual files through the dini...
Then, how i can readapt all my gm for dini²? Because exists several script lines with dini! :s

Sorry bad english :-[

Do you already have dini-user-files? In that case you need a converter.

For the script dini to djson conversion: very simple :).
dini_Int becomes to djInt
dini_IntSet becomes to djSetInt
dini_Get becomes to dj
dini_Set becomes to djSet
and so on, parameters stay the same.

Special: dini_Exists is not required, you may need fexists for that.

A good read, may be the functions-page (http://dev.dracoblue.net/index.php/DJson#Functions) for djson, so you get what the functions do and will know how to adapt them.

- Draco

Cezar
31/01/2009, 12:10 PM
I think it was asked and I missed it, hopefully not. Is DJson faster than pawno's file system?

DracoBlue
31/01/2009, 12:21 PM
I think it was asked and I missed it, hopefully not. Is DJson faster than pawno's file system?

DJson uses the pawno file system for initial read of the data. So if you are loading one big file _once_ and thats all: native pawno is faster.
But if you want to write a specific part of the file, or read several times (this is where djson uses memory-cache - no file read needed anymore) or commit lots of changes in a batch - djson is way faster.

- Draco

jwload
31/01/2009, 05:49 PM
Thks for reply Draco... ;)
I got convert my gm... But I have a problem...
The data in the files were not loaded :s
Djson can load data in file as Dini? In each line?


PlayerName=NoPlayerName
HealthSpawn=70
Money=145789
Deaths=7
Kills=15


I have like this several files this way... A file for each player, for each car, for each house, for each property :s

DracoBlue
01/02/2009, 10:02 PM
Thks for reply Draco... ;)
I got convert my gm... But I have a problem...
The data in the files were not loaded :s
Djson can load data in file as Dini? In each line?


PlayerName=NoPlayerName
HealthSpawn=70
Money=145789
Deaths=7
Kills=15


I have like this several files this way... A file for each player, for each car, for each house, for each property :s




Hello JwLoaDing,

actually djson can not load dini files. It's a completely different (thatswhy faster :)) file format.

I try to put a converter together for you, so you can easily convert your ini files to djson!

- Draco

jwload
02/02/2009, 03:26 PM
Thanks again, draco :D

I think I would get to do a function to convert the files of the cars, houses and properties because they are nominated for a numeric sequence, then with a loop I repeat the conversion procedure for each file... But, for the players whose files are nominated for the players' names I would have to do conversion file for file manually :s

I will wait for a converter, I think that should be simple for you ;)

pen_theGun
12/02/2009, 10:30 PM
Morgen Dracoblue,

i have some trouble with json, admittedly i know how to set: {"data":[{"1":"2"},{"3":"4"}]}
but i would realy like to know, how to create something similiar to this: {"data":[1,2,3,4]}

I hope you can help me out with this.

Danke! ;)

MfG pen_theGun.

DracoBlue
12/02/2009, 10:37 PM
Hi!

What you are about to do is to create an array, because [ and ] indictes that it is an array.

I made a short explanation how to access/write/count arrays in the djson-dev-wiki (http://dev.dracoblue.net/index.php/DJson/Tweaking#Using_djCount.2C_djAppend_and_djson_with_ arrays.28lists.29). Hope it helps - if it doesn't - ask again ;)!

- Draco

pen_theGun
13/02/2009, 07:57 PM
Dracoblue, i already re-read this (http://dev.dracoblue.net/index.php/DJson) and this (http://dev.dracoblue.net/index.php/DJson/Tweaking) many, many times and yes i can 'count' and 'read', but still can't create somethink like this --> {"data":[1,2,3,4]}

DracoBlue
14/02/2009, 10:38 AM
Dracoblue, i already re-read this (http://dev.dracoblue.net/index.php/DJson) and this (http://dev.dracoblue.net/index.php/DJson/Tweaking) many, many times and yes i can 'count' and 'read', but still can't create somethink like this --> {"data":[1,2,3,4]}

Let's guess we have a simple file, not yet created, you can use the following to create that file:

djAppend("file.json","data","1")
djAppend("file.json","data","2")
djAppend("file.json","data","3")
djAppend("file.json","data","4")

Gives you a file looking like that:
{"data":["1","2","3","4"]}

If you want a real "int"-array, you may use:

djSetInt("file.json","data/0",1)
djSetInt("file.json","data/1",2)
djSetInt("file.json","data/2",3)
djSetInt("file.json","data/3",4)

This is a pretty difficult read, so maybe I should add a djAppendInt, djAppendFloat and djAppendBool?

- Draco

pen_theGun
14/02/2009, 03:21 PM
djAppend("file.json","data","1")
djSetInt("file.json","data/0",1)

Well, now i see how it works. 8)
Thank you! ;)

This is a pretty difficult read, so maybe I should add a djAppendInt, djAppendFloat and djAppendBool?
I think that would be great.
PS:DracoBlue, thanks in advance, if you will do that. :)

On_Top_Non_Stop
07/04/2009, 02:40 PM
Never mind. It was my mistake.

ICECOLDKILLAK8
07/04/2009, 02:43 PM
Is the use of " " in data fixed yet?

NeRoSiS
07/04/2009, 06:42 PM
Hey, firstly, by the look of this it is amazing, and you have changed SAMP due to many of your includes from what I can tell. In a positive way that is.

I'm getting okay with scripting now, I can do quite a lot, just not userfiles, and it is the one thing I need to learn desperately, this seems simple, if not it is the best, so I guess I am asking if there are any tutorials or anything to get me using DJson, as userfiles would allow me to publish a lot of my work by finishing them off by making things save....

Anyway, great one DracoBlue, and thanks to any one who can help.

DracoBlue
07/04/2009, 08:07 PM
Hey, firstly, by the look of this it is amazing, and you have changed SAMP due to many of your includes from what I can tell. In a positive way that is.
Thank you! Glad to hear!


Is the use of " " in data fixed yet?

In which case it is broken? There is still an issue with writing " inside of strings, but anything else should work like a charm.

I'm getting okay with scripting now, I can do quite a lot, just not userfiles, and it is the one thing I need to learn desperately, this seems simple, if not it is the best, so I guess I am asking if there are any tutorials or anything to get me using DJson, as userfiles would allow me to publish a lot of my work by finishing them off by making things save....
I did some small summary here and there, but maybe we can work out some kind of example which helps you understanding? In general there is the documentation page (http://dev.dracoblue.net/index.php/DJson#Example) (short article about all the features + example), api docs (http://dev.dracoblue.net/index.php/DJson#Functions) (all functions explained) and of course the tweaking page (http://dev.dracoblue.net/index.php/DJson/Tweaking) (explaining how to get even more out of djson).

- Draco

NeRoSiS
07/04/2009, 08:53 PM
Wow, so well documented, you really do tie up all the loose eds, I appreciate the links, should be able to pick it up from those.

Again thank you, I appreciate your help and your abilitys.

lavamike
02/05/2009, 10:27 PM
Hi, could I get a little bit of help? I'm making a register & login system using DJson. The only problem i'm having is with the password. I'm using Whirlpool cryptography for the password encryption. Y-Less made a plugin for it here: http://forum.sa-mp.com/index.php?topic=89418.0

Okay, so here is the problem, I can write the password and other registration information perfectly. If I were to open up the file i'm saving it in(Accounts.json) and look through it, I can see everything I wrote in /register. Here is what I see after using /register, before using /login.

{"Lavamike":{"AK":0,"AdminDuty":0,"ArmourCheck":0,"ArmourFix":0,"BaronID":0,"CashFix":1,"Commander":0,"Created":"5/2009/2 [Month/Day/Year]","FirstSpawn":1,"HealthFix":1,"IP":"24.45.60.242","Idiot":0,"LoggedIn":0,"Mini":0,"PosFix":1,"Posa":0,"Posx":0,"Posy":0,"Posz":0,"RC":0,"RPG":0,"RegCheck":1,"SPAWN":0,"SPAWNBUG":1,"SPAWNFIX":0,"Spotted":0,"TeamKills":0,"VHealthFix":0,"Warns":0,"WeaponCheck":0,"banana":0,"kill":0,"password":"AC1C196E84B05D59FAEA639D0CCCB6C16F7568E0943F4C94C6 48BD8EEFE5CF3978F8D4F99B1426E4CE3C6FA40E17CF68D6B8 6D42246333569B963FF4579C6355"}}

The data stored under "password" is the Whirlpool encrypted text of, "Test"

AC1C196E84B05D59FAEA639D0CCCB6C16F7568E0943F4C94C6 48BD8EEFE5CF3978F8D4F99B1426E4CE3C6FA40E17CF68D6B8 6D42246333569B963FF4579C6355 is 128 characters long.

Here is what I see after /login in the Accounts.json file.

{"Lavamike":{"AK":0,"AdminDuty":0,"ArmourCheck":0,"ArmourFix":0,"BaronID":0,"CashFix":1,"Commander":0,"Created":"5/2009/2 [Month/Day/Year]","FirstSpawn":1,"HealthFix":1,"IP":"24.45.60.242","Idiot":0,"LoggedIn":1,"Mini":0,"PosFix":1,"Posa":0,"Posx":0,"Posy":0,"Posz":0,"RC":0,"RPG":0,"RegCheck":1,"SPAWN":0,"SPAWNBUG":1,"SPAWNFIX":0,"Spotted":0,"TeamKills":0,"VHealthFix":0,"Warns":0,"WeaponCheck":0,"banana":0,"kill":0}}

As you can see, the entire password data has been completely deleted. As stated earlier I registered with the password "Test" I typed "/login lol" and it apparently said the password was correct even though it obviously isn't. Here is my code for /login..


dcmd_login(playerid, params[])
{
new PlayerName[24];
GetPlayerName(playerid, PlayerName, 24);
if(AccountExists(PlayerName))
{
if(AccountGetInt(PlayerName, "LoggedIn") == 1) return SendClientMessage(playerid, COLOR_RED, "You are already logged in!");
if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "/login password");
if(strlen(params) > 20) return SendClientMessage(playerid, COLOR_RED, "Password cannot be greater than 20 characters.");
if(strlen(params) < 3) return SendClientMessage(playerid, COLOR_RED, "Password cannot be less than 3 characters.");
print("0");
print("======================== DEBUG =======================");
print("1");
printf("params = %s", params);
print("2");
new buf[145];
print("3");
WP_Hash(buf, sizeof(buf), params);
print("4");
print(buf);
print("5");
new PwCheck[255];
print("6");
new str[55];
print("7");
format(str, sizeof(str), "%s/%s", PlayerName, params);
print("8");
format(PwCheck, sizeof(PwCheck), "%s", dj("accounts.json", str));
print("9");
print(PwCheck);
print("10");
if(strcmp(PwCheck, buf, false) == 0)
{
print("PASS");
new IP[32];
GetPlayerIp(playerid, IP, 32);
new day, month, year;
new DayString[30];
getdate(day, month, year);
format(DayString, sizeof(DayString), "%d/%d/%d [Month/Day/Year]", month, day, year);
AccountSetInt(PlayerName, "LoggedIn", 1);
printf("[LOGIN] %s - %s [%s]",PlayerName, IP, DayString);
SendClientMessage(playerid, COLOR_SUCCESS, "You have successfully logged in! You may now select your team.");
} else return SendClientMessage(playerid, COLOR_RED, "ERROR: INVALID PASSWORD!");
} else return SendClientMessage(playerid, COLOR_RED, "Account does not exist. Please use /register password.");
return 1;
}

As you will see below in the logs, when i have this:

print("9");
print(PwCheck);
print("10");


print(PwCheck); prints out "(null)"
here is the log..


[23:09:05] Incomming connection: IP Hidden
[23:09:05] [join] Lavamike has joined the server (0:IP Hidden)
[23:09:05] Clan Protection Checking...
[23:09:05] Lavamike Passed - CLAN PROTECTION
[23:09:05] *** Lavamike(0) has joined the server!
[23:09:05] Welcome, Lavamike! To Register Type: /register Password
[23:09:13]

Cars Loaded
[23:09:13]

Checking For Unspawned Cars...
[23:09:13]

CarCheck Done
[23:09:17] Account Created: Lavamike - Test
[23:09:17] AC1C196E84B05D59FAEA639D0CCCB6C16F7568E0943F4C94C6 48BD8EEFE5CF3978F8D4F99B1426E4CE3C6FA40E17CF68D6B8 6D42246333569B963FF4579C6355
[23:09:17] [REGISTER] Lavamike - IP Hidden [5/2009/2 [Month/Day/Year]]
[23:14:12] 0
[23:14:12] ======================== DEBUG =======================
[23:14:12] 1
[23:14:12] params = lol
[23:14:12] 2
[23:14:12] 3
[23:14:12] 4
[23:14:12] 22FB46E1955A8AEB31C59D79D887D02AF2D1BC4524E85AAFA2 455CC78BC0147B10DD477201D147E2F5CA910BB43D98232047 8B9D179DDDE85F4806497FE2EE68
[23:14:12] 5
[23:14:12] 6
[23:14:12] 7
[23:14:12] 8
[23:14:12] 9
[23:14:12] (null)
[23:14:12] 10
[23:14:12] PASS
[23:14:12] [LOGIN] Lavamike - IP Hidden [5/2009/2 [Month/Day/Year]]
Console input: exit
[23:16:23] --- Server Shutting Down.
[23:16:23] Unloading Cars...
[23:16:23]
*********************
* SA:MP DEBUG 0.2 *
[23:16:23] * -- SHUTDOWN *
*********************

[23:16:23] [part] Lavamike has left the server (0:0)
[23:16:23]
[23:16:23] ====================
[23:16:23]
[23:16:23] Whirlpool unloaded
[23:16:23]
[23:16:23] ====================
[23:16:23]



It would be VERY greatly appreciated if you could enlight me on why DJson is returning "(null)" and deleting the password data inside Accounts.json
I also have reason to belive dj(..); is deleting the password as I once tried adding in a print to display the password after it was set in /register and looking at the file password was gone. Taking away that print, the password is there.

P.S: Sorry for the lengthy post :P

DracoBlue
03/05/2009, 11:28 AM
No problem! This is lots of information, helping to track down the reason for the issue :)!

I think djson returns null, because you do:
format(str, sizeof(str), "%s/%s", PlayerName, params);
which should be:
format(str, sizeof(str), "%s/password", PlayerName);

Because params is the password, but you want to read the users key "password".

About the lost key-issue (in your case password):
- Do you have any #pragma dynamic inside your code?
- Do any of your functions in the dcmd_login set anything in the accounts.json?
- Could you add DJSON_cache_debug_print(); after you think the data is corrupted to your code, and show that it prints?
- Could you send me the implementation of dcmd_register? Maybe a djCommit is missing, or something like that.

[edit] I guess I found the reason :).
Please open your djson.inc and change DJSON_MAX_STRING to 512;
Reason for this is, that the internal djson cache allows a maximum of ~ 70 characters (255-filenamelength-keylength-170) for a value, if it's set to just 255. I'll come up with a fix for next version!

- Draco

lavamike
03/05/2009, 03:27 PM
That seems to have done it! Thanks for the very helpful and speedy reply! :mrgreen:

The setting and getting information with the /'s kinda confuses me sometimes, i think that's why I didn't notice it :P


Thanks a lot again ;)


-Mike



EDIT: I also wanted to ask how I go about adding DJson for use into a filterscript. I know somebody had asked this and you sent a pastebin linked which I tried following the directions on but ended up getting a bunch of strange errors. Is it possible you could explain it a little clearer? Thanks! :)

-Mike

shitbird
04/05/2009, 05:35 AM
can someone make a guide on how to make a register and login script with Djson?

DracoBlue
04/05/2009, 08:18 AM
That seems to have done it! Thanks for the very helpful and speedy reply! :mrgreen:

Nice!


I also wanted to ask how I go about adding DJson for use into a filterscript. I know somebody had asked this and you sent a pastebin linked which I tried following the directions on but ended up getting a bunch of strange errors. Is it possible you could explain it a little clearer? Thanks! :)
Djson was not possible in filterscripts by default, because the samp built in db-functions were not registered for filterscripts. Not sure if that's fixed, just try it your self! :)

But I think one may run into issues (because of the cachefile), running 2 djson filterscripts at the same time, so I'll see that I can make a solution for that.

- Draco

lavamike
04/05/2009, 08:23 PM
Djson was not possible in filterscripts by default, because the samp built in db-functions were not registered for filterscripts. Not sure if that's fixed, just try it your self! :)

But I think one may run into issues (because of the cachefile), running 2 djson filterscripts at the same time, so I'll see that I can make a solution for that.

- Draco


I only need it in one filterscript so that shouldn't be a problem. I will try to see if I can get it working and post/edit what happens :P
EDIT: I'll post tomorrow sometime what happens with the filterscript.


can someone make a guide on how to make a register and login script with Djson?


Sure, i'll post one in the scripting discussion soon, being I just got mine to work :P


EDIT: I'm done with the tutorial, hope it's useful! ;)
http://forum.sa-mp.com/index.php?topic=101405.0

Danny_Costelo
08/05/2009, 07:47 PM
Thanks alot, I'm using this now.

The only thing i don't like is the format of the words when opening the file, how can i remove the "" and {}?

The dini format was much better and easier to read, a seperate thing for each line.

like

Password:
Admin:
etc..

Is there any possible way I can make it like that? :s

DracoBlue
08/05/2009, 07:51 PM
Use: djStyled(true) (http://dev.dracoblue.net/index.php/DJson#djStyled)

will make it look like that:
{
'key': 'value'
}

- Draco

Danny_Costelo
08/05/2009, 08:23 PM
Use: djStyled(true) (http://dev.dracoblue.net/index.php/DJson#djStyled)

will make it look like that:
{
'key': 'value'
}

- Draco

Thanks alot, man. I'll look into it.

I appreciate the fast reply ;)

EDIT: #define DJSON_ALLOW_STYLED_OUTPUT, so I set this to 1(true)?

EDIT2: I tryed both false and true, I get the same result :s

DracoBlue
10/05/2009, 07:06 PM
Did you do djStyled(true); before doing a djSet or a djCommit? Of course this only works if you do for instance:
djStyled(true);
djSet("myfile.json","element/key","text");

Read more about it here: http://dev.dracoblue.net/index.php/DJson/Tweaking#Using.2FDisable_styled_output

- Draco

On_Top_Non_Stop
21/05/2009, 07:26 PM
What could i be doing wrong if the server starts to lag for 10 seconds or more at a time after the server's been running for a few days.

I save ~80 stats to the players file and i use djAutocommit. Every things fine for a day or two but then the lag builds up till i have no option but to reset the server.

DracoBlue
21/05/2009, 08:15 PM
What could i be doing wrong if the server starts to lag for 10 seconds or more at a time after the server's been running for a few days.

I save ~80 stats to the players file and i use djAutocommit. Every things fine for a day or two but then the lag builds up till i have no option but to reset the server.

You do djAutocommit(false); before saving and djAutocommit(false) after you saved _all_ information? Did you put all information into one file, or several once? How much users do you have in that file?

- Draco

On_Top_Non_Stop
21/05/2009, 11:18 PM
I do djAutocommit(false); ...Save all the data... djCommit the file then djAutocommit(true);

Is it ment to be djAutocommit(false); before and after saving?


How much users do you have in that file?

One user per file.

Danny_Costelo
21/06/2009, 04:04 AM
Uh, if a specific stat isnt being used for a long time, like "Password", it saves on registering, it will not save again, it checks once during the /login command, if it's not being used or saved in a long period of time, will it disappear from the file?, I seem to be having that issue.

TheSh@rk
21/06/2009, 08:34 AM
I also wanted to ask how I go about adding DJson for use into a filterscript. I know somebody had asked this and you sent a pastebin linked which I tried following the directions on but ended up getting a bunch of strange errors. Is it possible you could explain it a little clearer? Thanks! :)


Djson was not possible in filterscripts by default, because the samp built in db-functions were not registered for filterscripts. Not sure if that's fixed, just try it your self! :)

But I think one may run into issues (because of the cachefile), running 2 djson filterscripts at the same time, so I'll see that I can make a solution for that.

- Draco


About the cache file - can this issue be solved by giving a unique name to each cache file? Or maybe an other way, I can't think of?

DracoBlue
21/06/2009, 09:17 AM
About the cache file - can this issue be solved by giving a unique name to each cache file? Or maybe an other way, I can't think of?

Hey SharkyKH!

I'll look right now in that issue and post a version, which is capable of own djson-cachefile ;).

- Draco

DracoBlue
21/06/2009, 10:11 AM
DJson 1.6 released : http://dracoblue.net/dev/djson-16-released/142/

Today I want to announce a new release of DJson. The 1.6 is now using a different method to create the cache-file, which allows running multiple djson-scripts (like filterscripts) at the same time.

Also it features a method to define own DJSON_MAX_STRING (before include of djson), if you need really big content.

The internal djson cache allows a maximum of ~ 70 characters (255-filenamelength-keylength-170) for a value, if DJSON_MAX_STRING is set to just 255.

Head over to the official DJson page or directly to the djson 1.6 download.

- Draco

Joske_Vermeulen
22/06/2009, 11:15 AM
Uh, if a specific stat isnt being used for a long time, like "Password", it saves on registering, it will not save again, it checks once during the /login command, if it's not being used or saved in a long period of time, will it disappear from the file?, I seem to be having that issue.


keys and their values don't just disappear, you must have a function somewhere that makes it remove from the file

Danny_Costelo
22/06/2009, 03:29 PM
Uh, if a specific stat isnt being used for a long time, like "Password", it saves on registering, it will not save again, it checks once during the /login command, if it's not being used or saved in a long period of time, will it disappear from the file?, I seem to be having that issue.


keys and their values don't just disappear, you must have a function somewhere that makes it remove from the file

Alright, thanks, just wanted to make sure. ;)

DracoBlue
22/06/2009, 07:12 PM
Uh, if a specific stat isnt being used for a long time, like "Password", it saves on registering, it will not save again, it checks once during the /login command, if it's not being used or saved in a long period of time, will it disappear from the file?, I seem to be having that issue.


keys and their values don't just disappear, you must have a function somewhere that makes it remove from the file

Alright, thanks, just wanted to make sure. ;)

Actually "loosing" data may happen, if you have a too low DJSON_MAX_STRING defined. The default is 255 (which means, your values should be max ~ 70 of length).

If you have values, which are way bigger (for instance 128) you may define DJSON_MAX_STRING with a higher value.

For instance:
#define DJSON_MAX_STRING 512
#include <djson>

Will allow values up to 325 characters.

- Draco

Burridge
22/06/2009, 07:14 PM
Really nice, I might use this at some point.

Clicker7
23/06/2009, 12:34 PM
can you tell me what the problem here ?

if(UserText == dj(PlayerName, "Password"))
{
djSetInt(PlayerName, "LoggedIn", 1);
}
its give me this error :
error 033: array must be indexed (variable "UserText")

and if i do

if(123123 == dj(PlayerName, "Password"))
{
djSetInt(PlayerName, "LoggedIn", 1);
}
it gives me this error :
error 033: array must be indexed (variable "dj")

what wrong ?! thank you

Joske_Vermeulen
23/06/2009, 12:59 PM
can you tell me what the problem here ?

if(UserText == dj(PlayerName, "Password"))
{
djSetInt(PlayerName, "LoggedIn", 1);
}
its give me this error :
error 033: array must be indexed (variable "UserText")

and if i do

if(123123 == dj(PlayerName, "Password"))
{
djSetInt(PlayerName, "LoggedIn", 1);
}
it gives me this error :
error 033: array must be indexed (variable "dj")

what wrong ?! thank you


#1. UserText is a string, use strcmp to compare
#2. for 123123 you need to use numbers, so djInt(PlayerName, "Password"), but don't do this because I know you mean point #1.

arnutisz
23/06/2009, 01:17 PM
Is it possible to save and load a lot of vehicles from one file, with DJson?

DracoBlue
23/06/2009, 01:18 PM
]
Is it possible to save and load a lot of vehicles from one file, with DJson?

Yes, its made for this kind of tasks. Especially if you read them quite often.

- Draco

Clicker7
23/06/2009, 01:37 PM
can you tell me what the problem here ?

if(UserText == dj(PlayerName, "Password"))
{
djSetInt(PlayerName, "LoggedIn", 1);
}
its give me this error :
error 033: array must be indexed (variable "UserText")

and if i do

if(123123 == dj(PlayerName, "Password"))
{
djSetInt(PlayerName, "LoggedIn", 1);
}
it gives me this error :
error 033: array must be indexed (variable "dj")

what wrong ?! thank you


#1. UserText is a string, use strcmp to compare
#2. for 123123 you need to use numbers, so djInt(PlayerName, "Password"), but don't do this because I know you mean point #1.


thaks dude but i trying this :
if(strcmp(UserText, dj(PlayerName, "Password"), true) == 0)
{
djSetInt(PlayerName, "LoggedIn", 1);
SendClientMessage(playerid, COLOR_DBLUE, "You logged on !");
}
the password in the file is 123123
but its not matter what i type its give me "You logged on !"
and set logged in to 1 :\

DracoBlue
23/06/2009, 02:42 PM
I guess either the variable UserText or Password is empty. How do you fill those?

- Draco

arnutisz
23/06/2009, 02:44 PM
]
Is it possible to save and load a lot of vehicles from one file, with DJson?

Yes, its made for this kind of tasks. Especially if you read them quite often.

- Draco


Can you give an example? I don't know how to make it.

Grim_
23/06/2009, 02:49 PM
It'd take awhile to explain. Try looking at how the Godfather loads and saves vehicles.

DracoBlue
23/06/2009, 03:14 PM
]

]
Is it possible to save and load a lot of vehicles from one file, with DJson?

Yes, its made for this kind of tasks. Especially if you read them quite often.

- Draco


Can you give an example? I don't know how to make it.

Depends how you define your vehicles. You could put them all in a big djson-array, like that:

{
"vehicles": [
{"x":123.232,"y":123.123,"model":123},
{"x":123.232,"y":123.123,"model":124},
{"x":123.232,"y":123.123,"model":125},
{"x":123.232,"y":123.123,"model":126}
]
}

and read them by this:
new model[255];
new count = djCount("vehicles.json","vehicles);
for (i=0;i<count;i++) {
format(model,255,"vehicles/%d/model",i);
print(dj("vehicles.json",model));
}

what would print you:
123
124
125
126

In that way you could use all variables, for whatever you like to do. For instance creating a vehicle.

Read more about arrays at the djson page http://dev.dracoblue.net/index.php/DJson#Arrays .

Feel free to ask further questions ;)!

- Draco

arnutisz
23/06/2009, 04:28 PM
Well, I need to save them to file when I write "/savecar". I have created command. And every time when I type "/savecar" car's model and coords should write in a new line (I don't know ho to do that). I take a look at GF saving, and i don't know how to make it with djson. I tried to make it with dini, but dini don't have "dini_Append", so just replaces that line with car, but it doesn't care now, I want to do that with djson. And how to check is file exists with djson? i don't know how, so did that:

if(!dini_Exists("/Vehicles/VehSF.json"))
{
djCreateFile("/Vehicles/VehSF.json");
}

DracoBlue
23/06/2009, 04:44 PM
]
Well, I need to save them to file when I write "/savecar". I have created command. And every time when I type "/savecar" car's model and coords should write in a new line (I don't know ho to do that). I take a look at GF saving, and i don't know how to make it with djson. I tried to make it with dini, but dini don't have "dini_Append", so just replaces that line with car, but it doesn't care now, I want to do that with djson. And how to check is file exists with djson? i don't know how, so did that:

if(!dini_Exists("/Vehicles/VehSF.json"))
{
djCreateFile("/Vehicles/VehSF.json");
}



How to add new items:
// model_id = 123, x=123.12
new count = djCount("vehicles.json","vehicles);
format(tmp,255,"vehicles/%d/model",count);
djSetInt("vehicles.json",tmp,model_id);
format(tmp,255,"vehicles/%d/x",count);
djSetFloat("vehicles.json",tmp,x);
... and so on.

How to check if djson file exists? Check if the file exists!
if (!fexists("vehicles.json")) {
//...
}

- Draco

Clicker7
23/06/2009, 05:56 PM
I guess either the variable UserText or Password is empty. How do you fill those?

- Draco

new UserText[256];
UserText = strtok(cmdtext, idx);

DracoBlue
23/06/2009, 05:58 PM
I guess either the variable UserText or Password is empty. How do you fill those?

- Draco

new UserText[256];
UserText = strtok(cmdtext, idx);

And PlayerName?

- Draco

arnutisz
23/06/2009, 08:24 PM
Thanks for helping, but:

new tmp[255];
new Float:X, Float:Y, Float:Z, Float:A, model;
GetVehiclePos(GetVehicleModel(GetPlayerVehicleID(p layerid)), X, Y, Z);
GetVehicleZAngle(GetVehicleModel(GetPlayerVehicleI D(playerid)), A);
model = GetVehicleModel(GetPlayerVehicleID(playerid));
new count = djCount("/Vehicles/VehSF.json", "vehicles");
format(tmp, 255, "vehicles/%d/model", count);
djSetInt("/Vehicles/VehSF.json", tmp, model);
format(tmp, 255, "vehicles/%d/x", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Float:X);
format(tmp, 255, "vehicles/%d/y", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Float:Y);
format(tmp, 255, "vehicles/%d/z", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Float:Z);
format(tmp, 255, "vehicles/%d/a", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Float:A);


This saves only one car, if i save other car, it replaces previously saved car.

DracoBlue
23/06/2009, 09:21 PM
new count = djCount("/Vehicles/VehSF.json", "vehicles");

should be
new count = djCount("/Vehicles/VehSF.json", "vehicles") + 1;

I guess.

- Draco

Clicker7
24/06/2009, 07:43 AM
I guess either the variable UserText or Password is empty. How do you fill those?

- Draco

new UserText[256];
UserText = strtok(cmdtext, idx);

And PlayerName?

- Draco


new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, 21);

DracoBlue
24/06/2009, 11:56 AM
I guess either the variable UserText or Password is empty. How do you fill those?

- Draco

new UserText[256];
UserText = strtok(cmdtext, idx);

And PlayerName?

- Draco


new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, 21);

So you have a file called "DracoBlue" in your scriptfiles folder, holding the data? May you show that too us, since I think it's empty -> strcmp returns 0, because the Password is empty.

- Draco

Clicker7
24/06/2009, 12:23 PM
I guess either the variable UserText or Password is empty. How do you fill those?

- Draco

new UserText[256];
UserText = strtok(cmdtext, idx);

And PlayerName?

- Draco


new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, 21);

So you have a file called "DracoBlue" in your scriptfiles folder, holding the data? May you show that too us, since I think it's empty -> strcmp returns 0, because the Password is empty.

- Draco

{"HP":"100","Location":["X","Y","Z"],"LoggedIn":0,"password":"123123"}
if (strcmp(cmd, "/register", true) ==0 )
{
new UserText[256];
UserText = strtok(cmdtext, idx);
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, 21); // Store the name to the PlayerName array.
if(!djIsSet(PlayerName,"password",false)) // Check if the account exists.
{
if(!strlen(UserText)) return SendClientMessage(playerid, COLOR_DBLUE, "/register password [Password is CaSE SeNSiTivE]");
if(strlen(UserText) > 20) return SendClientMessage(playerid, COLOR_DBLUE, "Password cannot be greater than 20 characters.");
if(strlen(UserText) < 3) return SendClientMessage(playerid, COLOR_DBLUE, "Password cannot be less than 3 characters.");
djStyled(true);
djSet(PlayerName,"password",UserText);
djAutocommit(false);
djSetInt(PlayerName, "LoggedIn", 0);
djSet(PlayerName,"HP","100");
djAppend(PlayerName,"Location","X");
djAppend(PlayerName,"Location","Y");
djAppend(PlayerName,"Location","Z");
djCommit(PlayerName);
djAutocommit(true);
SendClientMessage(playerid, COLOR_DBLUE, "You have successfully registered! You may now use /login password to login.");
}
else if(djInt(PlayerName, "LoggedIn") == 0) return SendClientMessage(playerid, COLOR_DBLUE, "Account already exists. Please use /login password to login.");
else return SendClientMessage(playerid, COLOR_DBLUE, "You are already logged on!");
return 1;
}

DracoBlue
24/06/2009, 12:30 PM
You set the password-key lowercase here:
djSet(PlayerName,"password",UserText);

but read it uppercase (why it's empty): dj(PlayerName, "Password")

- Draco

arnutisz
24/06/2009, 03:14 PM
Still not work:

stock SaveVehicleToFile(playerid)
{
new tmp[255];
new Float:X, Float:Y, Float:Z, Float:A, model;
GetVehiclePos(GetPlayerVehicleID(playerid), X, Y, Z);
GetVehicleZAngle(GetPlayerVehicleID(playerid), A);
model = GetVehicleModel(GetPlayerVehicleID(playerid));
new count = djCount("/Vehicles/VehSF.json", "vehicles")+1;
format(tmp, 255, "vehicles/%d/model", count);
djSetInt("/Vehicles/VehSF.json", tmp, model);
format(tmp, 255, "vehicles/%d/x", count);
djSetFloat("/Vehicles/VehSF.json", tmp, X);
format(tmp, 255, "vehicles/%d/y", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Y);
format(tmp, 255, "vehicles/%d/z", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Z);
format(tmp, 255, "vehicles/%d/a", count);
djSetFloat("/Vehicles/VehSF.json", tmp, A);
return 1;
}


And it writes to file this:

{"vehicles":{"1":{"a":138.472961,"model":522,"x":-1510.411499,"y":722.246215,"z":45.193630}}}


But I made 5 car saves. It saves only one car.

Clicker7
24/06/2009, 03:57 PM
You set the password-key lowercase here:
djSet(PlayerName,"password",UserText);

but read it uppercase (why it's empty): dj(PlayerName, "Password")

- Draco


tanks dude its work !!
but now i have another problem i write values to file and i get something else
if i do :

set(PlayerData[playerid][hp], "120")
set(PlayerData[playerid][pos_x], "0")
set(PlayerData[playerid][pos_y], "1")
set(PlayerData[playerid][pos_z], "0")



new FileData[32];
set(FileData, PlayerData[playerid][hp]); djSet(PlayerName,"HP", FileData);
set(FileData, PlayerData[playerid][pos_x]); djSet(PlayerName,"Postion/X", FileData);
set(FileData, PlayerData[playerid][pos_y]); djSet(PlayerName,"Postion/Y", FileData);
set(FileData, PlayerData[playerid][pos_z]); djSet(PlayerName,"Postion/Z", FileData);

i get this :
{
"HP":"1010",
"Postion":{
"X":"1010",
"Y":"10",
"Z":"0"
}
}

and another thing
if i do :
djSetInt(PlayerName,"HP", FileData);
and put to FileData Integer its just dont work
tag mismatch or something

arnutisz
24/06/2009, 04:05 PM
You set the password-key lowercase here:
djSet(PlayerName,"password",UserText);

but read it uppercase (why it's empty): dj(PlayerName, "Password")

- Draco


tanks dude its work !!
but now i have another problem i write values to file and i get something else
if i do :

set(PlayerData[playerid][hp], "120")
set(PlayerData[playerid][pos_x], "0")
set(PlayerData[playerid][pos_y], "1")
set(PlayerData[playerid][pos_z], "0")



new FileData[32];
set(FileData, PlayerData[playerid][hp]); djSet(PlayerName,"HP", FileData);
set(FileData, PlayerData[playerid][pos_x]); djSet(PlayerName,"Postion/X", FileData);
set(FileData, PlayerData[playerid][pos_y]); djSet(PlayerName,"Postion/Y", FileData);
set(FileData, PlayerData[playerid][pos_z]); djSet(PlayerName,"Postion/Z", FileData);

i get this :
{
"HP":"1010",
"Postion":{
"X":"1010",
"Y":"10",
"Z":"0"
}
}

and another thing
if i do :
djSetInt(PlayerName,"HP", FileData);
and put to FileData Integer its just dont work
tag mismatch or something



Try to use djSetFloat for pos and health

Clicker7
24/06/2009, 04:19 PM
]


You set the password-key lowercase here:
djSet(PlayerName,"password",UserText);

but read it uppercase (why it's empty): dj(PlayerName, "Password")

- Draco


tanks dude its work !!
but now i have another problem i write values to file and i get something else
if i do :

set(PlayerData[playerid][hp], "120")
set(PlayerData[playerid][pos_x], "0")
set(PlayerData[playerid][pos_y], "1")
set(PlayerData[playerid][pos_z], "0")



new FileData[32];
set(FileData, PlayerData[playerid][hp]); djSet(PlayerName,"HP", FileData);
set(FileData, PlayerData[playerid][pos_x]); djSet(PlayerName,"Postion/X", FileData);
set(FileData, PlayerData[playerid][pos_y]); djSet(PlayerName,"Postion/Y", FileData);
set(FileData, PlayerData[playerid][pos_z]); djSet(PlayerName,"Postion/Z", FileData);

i get this :
{
"HP":"1010",
"Postion":{
"X":"1010",
"Y":"10",
"Z":"0"
}
}

and another thing
if i do :
djSetInt(PlayerName,"HP", FileData);
and put to FileData Integer its just dont work
tag mismatch or something



Try to use djSetFloat for pos and health

if i use "FileData"
i can use only djSet other things just dont work

DracoBlue
24/06/2009, 04:59 PM
How is this PlayerData[][] field filled?

Guess you are using a string here, and setting it wrong. If it would be a int/float it would work with djSetFloat or djSetInt.

- Draco

arnutisz
24/06/2009, 05:46 PM
]
Still not work:

stock SaveVehicleToFile(playerid)
{
new tmp[255];
new Float:X, Float:Y, Float:Z, Float:A, model;
GetVehiclePos(GetPlayerVehicleID(playerid), X, Y, Z);
GetVehicleZAngle(GetPlayerVehicleID(playerid), A);
model = GetVehicleModel(GetPlayerVehicleID(playerid));
new count = djCount("/Vehicles/VehSF.json", "vehicles")+1;
format(tmp, 255, "vehicles/%d/model", count);
djSetInt("/Vehicles/VehSF.json", tmp, model);
format(tmp, 255, "vehicles/%d/x", count);
djSetFloat("/Vehicles/VehSF.json", tmp, X);
format(tmp, 255, "vehicles/%d/y", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Y);
format(tmp, 255, "vehicles/%d/z", count);
djSetFloat("/Vehicles/VehSF.json", tmp, Z);
format(tmp, 255, "vehicles/%d/a", count);
djSetFloat("/Vehicles/VehSF.json", tmp, A);
return 1;
}


And it writes to file this:

{"vehicles":{"1":{"a":138.472961,"model":522,"x":-1510.411499,"y":722.246215,"z":45.193630}}}


But I made 5 car saves. It saves only one car.


Mine still doesn't work.

Danny_Costelo
24/06/2009, 11:18 PM
Hey there.

How can I save a string into Djson, while loading, like this for example djInt(UserFile, "Time Online", str);, I want to load the 'Time Online' from the user file, not reset the value, using djInt gives me an error.

Works with DjSet, but the value changes during gameplay.

EDIT: Solved.

DracoBlue
25/06/2009, 06:12 AM
EDIT: Solved.

*smiles* How you fixed it? Wrong type for the pawn variable?

- Draco

MPKaboose
09/08/2009, 07:24 PM
I have some problems here recently I have tried to convert my code to use DjSon but
stock Get_Var(category[],name[],key[])
{
new str[64];
format(str,sizeof(str),"%s/%s/%s",category,name,key);
return djInt("ncrp.database.xml",str);
}I use that asGet_Var("User",Player[playerid][PD_Name],"Regnumber")=Player[playerid][PD_Regnumber];but I get these errorserror 022: must be lvalue (non constant)
warning 215: expression has no effecta bit of help would be needed, thanks

DracoBlue
09/08/2009, 07:28 PM
You are assigning a value to a function call ;).

Player[playerid][PD_Regnumber] = Get_Var("User",Player[playerid][PD_Name],"Regnumber");

This should be more like you want it?

- Draco

MPKaboose
09/08/2009, 07:33 PM
You are assigning a value to a function call ;).

Player[playerid][PD_Regnumber] = Get_Var("User",Player[playerid][PD_Name],"Regnumber");

This should be more like you want it?

- Draco
I'm like wow that was a really fast replay and yes it worked thanks :)

Zeex
24/08/2009, 10:57 AM
http://dev.dracoblue.net/index.php/DJson#Functions"][/url]
djson_GameModeExit ()
Destroys the djson-Engine, _must_ be executed on gamemode exit!
djson_GameModeInit ()
Initializes the djson-Engine, _must_ be executed on gamemode init!

http://forum.sa-mp.com/index.php?topic=110767.0

DracoBlue
24/08/2009, 09:29 PM
http://dev.dracoblue.net/index.php/DJson#Functions"][/url]
djson_GameModeExit ()
Destroys the djson-Engine, _must_ be executed on gamemode exit!
djson_GameModeInit ()
Initializes the djson-Engine, _must_ be executed on gamemode init!

http://forum.sa-mp.com/index.php?topic=110767.0

I use dmodule to write "modules". This release and all other libraries is just for those, without dmodule. There is a filterscript limit, because there is a filterscript limit ;).

- Draco

Joske_Vermeulen
02/09/2009, 03:13 PM
Hi Draco, time for compatibility with 0.3 :mrgreen:

EDIT: it works fine with current 0.3 beta, glad to see
I made a mistake somewhere

DracoBlue
08/09/2009, 06:49 AM
EDIT: it works fine with current 0.3 beta, glad to see
I made a mistake somewhere

Good to know!

- Draco

RyDeR`
08/09/2009, 10:23 AM
Very nice, I love al of your work :P

x-cutter
13/09/2009, 08:02 PM
Hi Dracoblue.

I'm making a script and I'm not sure I'm using djson like it should.
Could you take a look at this script? (http://pastebin.com/m784f3f72)
I did put djson_OnGamemodeinit or whatsoever before using this function.

The problem is that the vehicle doesn't get created... or gets deleted after creation.
The problem shouldn't be inside the "else" brackets.

Thanks for helping!

PS: Great work for this include!

DracoBlue
13/09/2009, 09:20 PM
Hi Dracoblue.

I'm making a script and I'm not sure I'm using djson like it should.
Could you take a look at this script? (http://pastebin.com/m784f3f72)
I did put djson_OnGamemodeinit or whatsoever before using this function.

The problem is that the vehicle doesn't get created... or gets deleted after creation.
The problem shouldn't be inside the "else" brackets.

Thanks for helping!

PS: Great work for this include!

Hi there,

first of all, you don't need to use the no-cache-flag always.
djRevert(str)
does revert all possible cached data.



Is the WSSFILES/CARDATA/0.xcu file created, and what is its content?

- Draco

x-cutter
13/09/2009, 09:29 PM
Hi Dracoblue.

I'm making a script and I'm not sure I'm using djson like it should.
Could you take a look at this script? (http://pastebin.com/m784f3f72)
I did put djson_OnGamemodeinit or whatsoever before using this function.

The problem is that the vehicle doesn't get created... or gets deleted after creation.
The problem shouldn't be inside the "else" brackets.

Thanks for helping!

PS: Great work for this include!

Hi there,

first of all, you don't need to use the no-cache-flag always.
djRevert(str)
does revert all possible cached data.



Is the WSSFILES/CARDATA/0.xcu file created, and what is its content?

- Draco


Well I used this no-cache thing to see if the cache was actually a problem. But I figured the problem myself, I saved a value for Vehicletype but loaded it as VehicleType, so it just returned to me some crap, so the vehicles didn't create because of their invalid model id.

- Thanks though

Great Include :D

DracoBlue
13/09/2009, 09:41 PM
- Thanks though

Great Include :D

Ah nice! Thanks!

Have fun coding,
Draco

Danny_Costelo
15/11/2009, 12:01 AM
How would I change a player's file name ingame? djset?

DracoBlue
15/11/2009, 06:12 PM
How would I change a player's file name ingame? djset?

depends on how you save the name. How do you save it?

Have fun coding,
Draco

Danny_Costelo
21/11/2009, 03:57 PM
How would I change a player's file name ingame? djset?

depends on how you save the name. How do you save it?

Have fun coding,
Draco

format(UserFile, sizeof(UserFile), "SE/Accounts/%s.json", name);
djCreateFile(UserFile);
How would I rename the "%s.json"?

DracoBlue
21/11/2009, 04:40 PM
How would I change a player's file name ingame? djset?

depends on how you save the name. How do you save it?

Have fun coding,
Draco

format(UserFile, sizeof(UserFile), "SE/Accounts/%s.json", name);
djCreateFile(UserFile);
How would I rename the "%s.json"?

using frename

- Draco

Danny_Costelo
21/11/2009, 05:52 PM
How would I change a player's file name ingame? djset?

depends on how you save the name. How do you save it?

Have fun coding,
Draco

format(UserFile, sizeof(UserFile), "SE/Accounts/%s.json", name);
djCreateFile(UserFile);
How would I rename the "%s.json"?

using frename

- Draco

I can't find that function on the wiki, is there any documentation or example of it?

DracoBlue
21/11/2009, 07:35 PM
Ah, its part of dutils. If you want to use it on linux, I suggest you use frenametextfile.

/**
* Renames a file (Source file will be deleted!)
* @param oldname
* newname
*/
stock frenametextfile(oldname[],newname[])

Maybe I should add a file to do that to the djson library, since it's even faster if you do it directly with djson's cache.

- Draco

Danny_Costelo
22/11/2009, 05:56 AM
Thanks, I'll wait till you do so, no rush ;)

Joske_Vermeulen
22/11/2009, 03:11 PM
I wonder if djson works in filterscripts now..

Donuts
26/11/2009, 07:17 PM
I have all this info
enum cdInfo
{
cdOwned,
cdOwner[MAX_PLAYER_NAME],
Float: cdEntranceX,
Float: cdEntranceY,
Float: cdEntranceZ,
Float: cdExitX,
Float: cdExitY,
Float: cdExitZ,
cdMessage[128],
cdTill,
cdInterior,
cdVehicleModel[MAX_DEALERSHIPVEHICLES],
cdVehicleCost[MAX_DEALERSHIPVEHICLES],
cdVehicleId[MAX_DEALERSHIPVEHICLES],
Float: cdVehicleSpawnX[MAX_DEALERSHIPVEHICLES],
Float: cdVehicleSpawnY[MAX_DEALERSHIPVEHICLES],
Float: cdVehicleSpawnZ[MAX_DEALERSHIPVEHICLES],
Float: cdVehicleSpawnAngle[MAX_DEALERSHIPVEHICLES],
Float: cdVehicleSpawn[4],
}
Could I do this?


"dealership0"{
"id":0,"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}
}
I don't really understand the structure of how should it be.

Edit:
I want it to be like this.
{
"0":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"1":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"2":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"3":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"4":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"5":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"6":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"7":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"8":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"9":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
}
Is this code good?

Donuts
26/11/2009, 08:36 PM
Ok I made some code and got thispublic LoadcDealership()
{
new idx;
new string[128];
new owner[MAX_PLAYER_NAME];
new message[128];
while (idx < sizeof(CarDealershipInfo))
{
format(string, sizeof(string), "%d/owned", idx);
CarDealershipInfo[idx][cdOwned] = djInt("cardealerships.json", string);
format(string, sizeof(string), "%d/owner", idx);
format(owner, sizeof(owner), "%s", dj("cardealerships.json", string));
strmid(CarDealershipInfo[idx][cdOwner], owner, 0, strlen(owner), 255);
format(string, sizeof(string), "%d/entrance/x", idx);
CarDealershipInfo[idx][cdEntranceX] = djFloat("cardealerships.json", string);
format(string, sizeof(string), "%d/entrance/y", idx);
CarDealershipInfo[idx][cdEntranceY] = djFloat("cardealerships.json", string);
format(string, sizeof(string), "%d/entrance/z", idx);
CarDealershipInfo[idx][cdEntranceZ] = djFloat("cardealerships.json", string);
format(string, sizeof(string), "%d/exit/x", idx);
CarDealershipInfo[idx][cdExitX] = djFloat("cardealerships.json", string);
format(string, sizeof(string), "%d/exit/y", idx);
CarDealershipInfo[idx][cdExitY] = djFloat("cardealerships.json", string);
format(string, sizeof(string), "%d/exit/z", idx);
CarDealershipInfo[idx][cdExitZ] = djFloat("cardealerships.json", string);
format(string, sizeof(string), "%d/message", idx);
format(message, sizeof(message), "%s", dj("cardealerships.json", string));
strmid(CarDealershipInfo[idx][cdMessage], message, 0, strlen(message), 255);
format(string, sizeof(string), "%d/till", idx);
CarDealershipInfo[idx][cdTill] = djInt("cardealerships.json", string);
format(string, sizeof(string), "%d/interior", idx);
CarDealershipInfo[idx][cdInterior] = djInt("cardealerships.json", string);
printf("DealershipId:%d Owner:%s Message:%s Till:%d Interior:%d EntranceX:%.1f EntranceY:%.1f EntranceZ:%.1f.\n",
idx,
CarDealershipInfo[idx][cdOwner],
CarDealershipInfo[idx][cdMessage],
CarDealershipInfo[idx][cdTill],
CarDealershipInfo[idx][cdInterior],
CarDealershipInfo[idx][cdEntranceX],
CarDealershipInfo[idx][cdEntranceY],
CarDealershipInfo[idx][cdEntranceZ]);
idx++;
}
return 1;
}

And it prints me this:
[13:33:07] DealershipId:0 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:1 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:2 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:3 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:4 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:5 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:6 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:7 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:8 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

[13:33:07] DealershipId:9 Owner: Message: Till:0 Interior:0 EntranceX:0.0 EntranceY:0.0 EntranceZ:0.0.

The info of the file is like I posted above.
Sorry for the spam

DracoBlue
26/11/2009, 10:26 PM
"dealership0"{
"id":0,"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}
}
I don't really understand the structure of how should it be.

Edit:
I want it to be like this.
{
"0":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"1":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"2":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"3":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"4":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"5":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"6":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"7":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"8":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
"9":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
}
Is this code good?

No. There is a , (comma) missing at the end of each line, try this:
{
"0":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"1":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"2":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"3":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"4":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"5":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"6":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"7":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"8":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}},
"9":{"owned":0,"owner":"Alex_Donuts","entrance":{"x":0.0,"y":0.0,"z":0.0},"exit":{"x":0.0,"y":0.0,"z":0.0},"message":"You suck","till":0,"interior":0,"vehicletypes":[0,0,0,0,0,0,0,0,0,0],"vehiclecost":[0,0,0,0,0,0,0,0,0,0],"vehiclespawnx":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawny":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawnz":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehicleangle":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"vehiclespawn":{"x":0.0,"y":0.0,"z":0.0,"a":0.0}}
}

You can always use a tool like json-indent ( http://json-indent.appspot.com/ ) to check wether it is a valid json file - or use the following to get file-problems in your .json file directly with djson:
CarDealershipInfo[idx][cdOwned] = djInt("cardealerships.json", string);
printf("DJSON_LastError #%d: %s",DJSON_LastErrorCode,DJSON_LastError);

Have fun coding,
Draco

Donuts
26/11/2009, 10:32 PM
[15:30:42] DJSON_LastError #1: Can not open file cardealerships.json

What's the problem?

DracoBlue
26/11/2009, 10:49 PM
Is cardealerships.json in the scriptfiles folder?

- Draco

MPKaboose
27/11/2009, 09:22 PM
it seems that
Player[ playerid ][ pSkin ] = djInt( iFile, "main/skin", false );
will always return 0 even if in the file its 250 what could be the actual reason for this, this also happens whit everything else excluding the stings (for passwords).

Fixed.

Donuts
27/11/2009, 10:02 PM
Indeed it is.

DracoBlue
28/11/2009, 09:28 AM
Indeed it is.

Then be sure that it's able (check read-permissions) to read that file (even with fopen or other file functions), because DJSON wouldn't throw that error in any other case.

Have fun coding,
Draco

MPKaboose
29/11/2009, 12:45 PM
strings only get saved if I use

djAutocommit( false );
djSet( iFile, "main/password", Player[ playerid ][ pPassword ] );
djCommit( iFile );
//djAutocommit( true ); you don't need these here
//djAutocommit( false );
djSetInt( iFile, "main/regid", Player[ playerid ][ pRegID ] );
// ...
djCommit( iFile );
djAutocommit( true );

but it wont if

djAutocommit( false );
djSet( iFile, "main/password", Player[ playerid ][ pPassword ] );
djSetInt( iFile, "main/regid", Player[ playerid ][ pRegID ] );
// ...
djCommit( iFile );
djAutocommit( true );

:| I don't know the reason why tough

DracoBlue
29/11/2009, 06:51 PM
strings only get saved if I use

djAutocommit( false );
djSet( iFile, "main/password", Player[ playerid ][ pPassword ] );
djCommit( iFile );
//djAutocommit( true ); you don't need these here
//djAutocommit( false );
djSetInt( iFile, "main/regid", Player[ playerid ][ pRegID ] );
// ...
djCommit( iFile );
djAutocommit( true );

but it wont if

djAutocommit( false );
djSet( iFile, "main/password", Player[ playerid ][ pPassword ] );
djSetInt( iFile, "main/regid", Player[ playerid ][ pRegID ] );
// ...
djCommit( iFile );
djAutocommit( true );

:| I don't know the reason why tough

What does:
printf("DJSON_LastError #%d: %s",DJSON_LastErrorCode,DJSON_LastError);
if you do that right after the djCommit?

Can you add a:
DJSON_cache_debug_print ()
before the djCommit, too?

- Draco
- Draco

MPKaboose
29/11/2009, 10:14 PM
[00:11:01] DJSON_LastError #1: Can not open file Onyx_Kowalsky.ini
[00:11:09] DJSON_LastError #0: The path main/password is not set
and
"password":""
it only saves the string if djCommit( filename[ ] ); is after the djSet( ... )

DiddyBop
30/11/2009, 03:32 AM
so your an M.I.T grad?!?! :O shouldnt u be creating the next microshit? :S

DracoBlue
05/12/2009, 06:41 PM
so your an M.I.T grad?!?! :O shouldnt u be creating the next microshit? :S

:D, the source is just under the terms of MIT License. Has nothing todo with the institute nor with microsoft ;).

- Draco

Joske_Vermeulen
05/12/2009, 07:13 PM
DracoBlue: I've sent you a PM a while ago, might check it some time ;)

Norn
19/02/2010, 05:31 PM
When i open the file it just shows {}, and i have used djson before without any problems.

Anyone got any idea why this isn't working?

#define SETTINGS_FILE "RP_Scriptfiles/settings.ini"

public LoadScript()
{
if(fexist(SETTINGS_FILE))
{
strmid(Settings[sServerName], dj(SETTINGS_FILE, "SERVER_SETTINGS/sServerName"), 0, 128, 128);
strmid(Settings[sPassword], dj(SETTINGS_FILE, "SERVER_SETTINGS/sPassword"), 0, 128, 128);
strmid(Settings[sMapName], dj(SETTINGS_FILE, "SERVER_SETTINGS/sMapName"), 0, 128, 128);
strmid(Settings[sWebsite], dj(SETTINGS_FILE, "SERVER_SETTINGS/sWebsite"), 0, 128, 128);
print("Script loading.... Loaded!");
return true;
}
else
{
//---------------------[SETTING DEFAULT VARIABLES]------------------------
format(Settings[sServerName], sizeof(Settings[sServerName]), "Default Server Name");
format(Settings[sPassword], sizeof(Settings[sServerName]), "");
format(Settings[sMapName], sizeof(Settings[sMapName]), "San Andreas");
format(Settings[sWebsite], sizeof(Settings[sServerName]), "http://sa-mp.com");
printf("%s, %s, %s, %s", Settings[sServerName], Settings[sPassword], Settings[sMapName], Settings[sWebsite]);
//------------------------------------------------------------------------
print("Script settings not found, creating file.");
fcreate(SETTINGS_FILE);
SaveScript();
}
return false;
}
public SaveScript()
{
if(fexist(SETTINGS_FILE))
{
djSet(SETTINGS_FILE,"SERVER_SETTINGS/sServerName",Settings[sServerName], true);
djSet(SETTINGS_FILE,"SERVER_SETTINGS/sPassword",Settings[sPassword], true);
djSet(SETTINGS_FILE,"SERVER_SETTINGS/sMapName",Settings[sMapName], true);
djSet(SETTINGS_FILE,"SERVER_SETTINGS/sWebsite",Settings[sWebsite], true);
djCommit(SETTINGS_FILE);
print("Saving script... Saved!");
return true;
}
else
{
print("Script settings not found, creating file.");
fcreate(SETTINGS_FILE);
SaveScript();
}
return false;
}

DracoBlue
20/02/2010, 09:18 AM
Please do that:
printf("DJSON: #%d %s",DJSON_LastErrorCode,DJSON_LastError);
after
djCommit(SETTINGS_FILE);
print("Saving script... Saved!");

And tell me what DJSON says!

- Draco

Donuts
20/02/2010, 10:06 AM
Why do I get my scriptfiles folder spammed with cache files? I don't know why this happens.

DracoBlue
20/02/2010, 10:18 AM
Why do I get my scriptfiles folder spammed with cache files? I don't know why this happens.

Maybe you forgot to add this:
public OnGameModeExit() {
djson_GameModeExit(); // <-- when you exit the gamemode, after that you can't run any djson function anymore!
return 1;
}

- Draco

[WSM]Deadly_Evil
20/02/2010, 01:51 PM
Good Work Draco :D

Norn
21/02/2010, 08:20 AM
Please do that:
printf("DJSON: #%d %s",DJSON_LastErrorCode,DJSON_LastError);
after
djCommit(SETTINGS_FILE);
print("Saving script... Saved!");

And tell me what DJSON says!

- Draco


I figured it out, i was using LoadScript(); before djson_GameModeInit().

Thanks anyway!

DracoBlue
21/02/2010, 11:41 AM
I figured it out, i was using LoadScript(); before djson_GameModeInit().

A good to know!

Have fun coding,
Draco

Kennu
21/02/2010, 04:51 PM
...

DracoBlue
21/02/2010, 05:01 PM
I have everything OK with DJSon but only little problem. How can i take info from Accounts.json and make it like in GodFather PlayerInfo. I have been working with DINI, there you can use ini_Getvalue but how is it with DJSon system?

Very Good Work, Draco! :) Thanks!

Waiting for answers,
Kevin.

It's even simplier, when you use dini_Get(filename[], key[]) you use dj(filename[], key[]). If you need an int, you did with dini like that: dini_Int(filename[],key[]) and do with djson this: djInt(filename[], key[]).

Have fun coding,
Draco

proG(r)a(m)mer
23/02/2010, 08:40 AM
graeat script

Nekom
06/03/2010, 06:26 PM
A question: if the key is not setted and I use dj or djInt what does it return?

DracoBlue
07/03/2010, 11:17 AM
A question: if the key is not setted and I use dj or djInt what does it return?

dj: Empty string
djInt: 0

Have fun codng,
Draco

Nekom
07/03/2010, 03:55 PM
I converted the dudb for the json. The result sucked! Server lags, not all variables saved and there were a lot of problems...

Rzzr
07/03/2010, 04:07 PM
I converted the dudb for the json. The result sucked! Server lags, not all variables saved and there were a lot of problems...


Then you did something wrong while converting

DracoBlue
07/03/2010, 04:18 PM
I converted the dudb for the json. The result sucked! Server lags, not all variables saved and there were a lot of problems...

Heya!

I can imagine that. Did you use djAutocommit(false) and djCommit then ;)?

- Draco

Nekom
07/03/2010, 04:34 PM
Yes, I used djAutoCommit(false) and than djCommit

DracoBlue
07/03/2010, 06:32 PM
Yes, I used djAutoCommit(false) and than djCommit

Ok, then maybe explain what you save by using djson and how often. Because djson outperforms way better in any case when you read multiple times or write a lots of data at once (by using djCommit).

- Draco

Nekom
08/03/2010, 02:27 PM
Using Dini + dudb I have some crashes... but I saved the values when changed
Using DJson + a modified version of dudb for it, putting in OnGameModeInit djAutocommit(false); and using djCommit(filename); only OnPlayerDisconnect (once file for player) and every 2 minutes the values aren't read well... Can you help me?

I'm working for a RP GM from scratch but I started with dudb and there are some server crashes T_T

Nekom
09/03/2010, 06:41 AM
up

DracoBlue
09/03/2010, 10:10 PM
...
the values aren't read well... Can you help me?
...
This means pretty much, that the values are not stored properly either. And this means, that you exceed some limits, which shouldn't be exceeded ;).

Please do that:
printf("DJSON: #%d %s",DJSON_LastErrorCode,DJSON_LastError);
after
djCommit();

And tell me what DJson says!

- Draco

Nekom
11/03/2010, 02:49 PM
...
the values aren't read well... Can you help me?
...
This means pretty much, that the values are not stored properly either. And this means, that you exceed some limits, which shouldn't be exceeded ;).

Please do that:
printf("DJSON: #%d %s",DJSON_LastErrorCode,DJSON_LastError);
after
djCommit();

And tell me what DJson says!

- Draco


- Draco


The Path Banned is not set

it's because i not setted it
If I try to read the key "Registered" it return 0, but it's setted to 1... in the file also it's setted to 1

I think it's a database problem

can you add me to msn (peppe_os_95@hotmail.it) please?

DracoBlue
12/03/2010, 07:28 PM
Send me the contents of the file as PM please.

- Draco

PS: I do not use MSN/ICQ/whatever

Norn
23/03/2010, 05:44 AM
Fixed, i didn't think you had to use djCommit when using djUnset.

GTAIV2008
23/03/2010, 01:07 PM
Regarding the examples at the beginning:
For what reason do you turn Autocommit off and on again instead of just turning it off once and always using djCommit?

Norn
24/03/2010, 12:58 AM
Regarding the examples at the beginning:
For what reason do you turn Autocommit off and on again instead of just turning it off once and always using djCommit?


I noticed that, i just turn it off and use djCommit like you said.

DracoBlue
24/03/2010, 08:29 PM
Regarding the examples at the beginning:
For what reason do you turn Autocommit off and on again instead of just turning it off once and always using djCommit?

The point is very good. Actually most guys use djSet most time and want instant effect. So autocommit is fine for them. But if you think about your save-strategy enough, you'll come to the conclusion that a periodical djCommit is way better then autocommiting all time ;).

- Draco

Zamaroht
05/04/2010, 06:34 PM
Hey Draco!
So far I have used dini a lot of times (with some small modifications, to handle manually file opening and closing) and always resulted very reliable :)
Now I'm starting a new (and pretty long) full gamemode project, and I finally feel ready to take a step further and make full use out of the DJson library for every saving system.
Thanks very much for this release, keep up the good amazing work.

Zamaroht
27/04/2010, 01:13 AM
I came up with a problem similar to the one you explained here:


]
Well, I need to save them to file when I write "/savecar". I have created command. And every time when I type "/savecar" car's model and coords should write in a new line (I don't know ho to do that). I take a look at GF saving, and i don't know how to make it with djson. I tried to make it with dini, but dini don't have "dini_Append", so just replaces that line with car, but it doesn't care now, I want to do that with djson. And how to check is file exists with djson? i don't know how, so did that:

if(!dini_Exists("/Vehicles/VehSF.json"))
{
djCreateFile("/Vehicles/VehSF.json");
}



How to add new items:
// model_id = 123, x=123.12
new count = djCount("vehicles.json","vehicles);
format(tmp,255,"vehicles/%d/model",count);
djSetInt("vehicles.json",tmp,model_id);
format(tmp,255,"vehicles/%d/x",count);
djSetFloat("vehicles.json",tmp,x);
... and so on.

How to check if djson file exists? Check if the file exists!
if (!fexists("vehicles.json")) {
//...
}

- Draco



I'm in the need of creating a json array with the following syntax:

"Array":[{"Stuff1":"String", "Stuff2": 3},{"Stuff1":"String2", "Stuff2": 4}]

The problem comes with creating the array. If it already exists, I can just use djSet, and the paths "Array/0/Stuff1", "Array/0/Stuff2", "Array/1/Stuff1" and "Array/1/Stuff2". But in case it doesn't exist, if I use these same functions, it creates objects instead of the array itself. Something with a syntax similar to:

"Array":{"1":{"Stuff1":"String", "Stuff2": 3},"2":{"Stuff1":"String2", "Stuff2": 4}}

So, the question is, how can I create an object-containing array from pawn using DJson, without it alreay existing?

DracoBlue
27/04/2010, 08:22 AM
I came up with a problem similar to the one you explained here:


]
Well, I need to save them to file when I write "/savecar". I have created command. And every time when I type "/savecar" car's model and coords should write in a new line (I don't know ho to do that). I take a look at GF saving, and i don't know how to make it with djson. I tried to make it with dini, but dini don't have "dini_Append", so just replaces that line with car, but it doesn't care now, I want to do that with djson. And how to check is file exists with djson? i don't know how, so did that:

if(!dini_Exists("/Vehicles/VehSF.json"))
{
djCreateFile("/Vehicles/VehSF.json");
}



How to add new items:
// model_id = 123, x=123.12
new count = djCount("vehicles.json","vehicles);
format(tmp,255,"vehicles/%d/model",count);
djSetInt("vehicles.json",tmp,model_id);
format(tmp,255,"vehicles/%d/x",count);
djSetFloat("vehicles.json",tmp,x);
... and so on.

How to check if djson file exists? Check if the file exists!
if (!fexists("vehicles.json")) {
//...
}

- Draco



I'm in the need of creating a json array with the following syntax:

"Array":[{"Stuff1":"String", "Stuff2": 3},{"Stuff1":"String2", "Stuff2": 4}]

The problem comes with creating the array. If it already exists, I can just use djSet, and the paths "Array/0/Stuff1", "Array/0/Stuff2", "Array/1/Stuff1" and "Array/1/Stuff2". But in case it doesn't exist, if I use these same functions, it creates objects instead of the array itself. Something with a syntax similar to:

"Array":{"1":{"Stuff1":"String", "Stuff2": 3},"2":{"Stuff1":"String2", "Stuff2": 4}}

So, the question is, how can I create an object-containing array from pawn using DJson, without it alreay existing?


Hello,

this function:
DJSON_cache_updateArrayNode(file[], key[])
is used when you touch the array with djAppend for the first time.

Try to use that function if the array does not exist, yet.

DJson should definately offer a public function for that. There will be a new release within next days (due 2 issues some people ran into), maybe I'll add a method to create a new array, too.

Have fun coding,
Draco

Zamaroht
27/04/2010, 02:10 PM
Hello,

this function:
DJSON_cache_updateArrayNode(file[], key[])
is used when you touch the array with djAppend for the first time.

Try to use that function if the array does not exist, yet.

DJson should definately offer a public function for that. There will be a new release within next days (due 2 issues some people ran into), maybe I'll add a method to create a new array, too.

Have fun coding,
Draco


I tried that function, but it seemed to do nothing if the array didn't exist. Instead, I was able to create an empty array by using
DJSON_cache_createArrayNode(file[], key[], 0);
And then add the object values to it by using djSet, and it seems to work correctly. djCount counts the objects correctly too.

Thank you.

DracoBlue
06/05/2010, 09:23 PM
DJson 1.6.1 released.

http://dracoblue.net/dev/djson-161-released/169/

Thanks to Raphinity for the bug report!

Have fun coding,
Draco

DracoBlue
08/05/2010, 09:09 AM
DJson 1.6.1 released.

http://dracoblue.net/dev/djson-161-released/169/

Thanks to Raphinity for the bug report!

Have fun coding,
Draco


And again, DJson 1.6.2 released.

Blogpost: http://dracoblue.net/dev/djson-162-released/169/
Changelog: http://dev.dracoblue.net/index.php/DJson/Changelog

Thanks to Zamaroht for the bug report!

Have fun coding,
Draco

Joske_Vermeulen
19/05/2010, 02:42 PM
thank you dracoblue, this was actually the problem I asked you over pm dracoblue which wasn't the "over-memory-use-that-breaks-it-problem"

MisterTickle
30/05/2010, 06:12 PM
So DJAutoCommit should be used before/after large batch loads/saves like at the beggining of a Gamemode when vehicles or loaded or such? What exactly is this doing and why does it make things run faster?

Converting my DudB/Dini code to Djson so I'm just trying to understand whats going on, Thanks Draco, I really love all of your releases by the way, Its been a while since you released something new, Have a go at something new. ;)

Zamaroht
30/05/2010, 08:25 PM
So DJAutoCommit should be used before/after large batch loads/saves like at the beggining of a Gamemode when vehicles or loaded or such? What exactly is this doing and why does it make things run faster?


As far as I know, DJAutoCommit just affects save operations.
When it is turned off, every time you save a line to a file, it opens the file, saves the line, and closes the file. And it repeats it every time you save something.
When it is turned off, it doesn't save the line to the file, but instead it saves it into the cache, which is accesed a lot faster. Then, when you do djCommit, it parses all the unsaved contents from the cache to the file.
Remember to turn back on djAutoCommit at the end of every large saving.

DracoBlue
31/05/2010, 06:10 AM
So DJAutoCommit should be used before/after large batch loads/saves like at the beggining of a Gamemode when vehicles or loaded or such? What exactly is this doing and why does it make things run faster?


As far as I know, DJAutoCommit just affects save operations.
When it is turned off, every time you save a line to a file, it opens the file, saves the line, and closes the file. And it repeats it every time you save something.
When it is turned off, it doesn't save the line to the file, but instead it saves it into the cache, which is accesed a lot faster. Then, when you do djCommit, it parses all the unsaved contents from the cache to the file.
Remember to turn back on djAutoCommit at the end of every large saving.

Yes.

Since in pawn it saving a file takes time, you use djAutoCommit to postpone the writing operation until everything is in the cache. A good practice is to make for instance one file for each player and not one big for all players. This allows you to save a single player way faster then all players at once. Djson can cache a pretty unlimited amount of files at the same time, so at reading time there is only little difference.

Have fun coding,
Draco

MisterTickle
31/05/2010, 04:31 PM
Thats what I'm trying to do but I'm having a bit of a problem, I modified the system that was posted above with the dudb conversion and for some reason it is not saving, Mind taking a look at it? Its strange, I had it working 100% at one point but I changed something while coding multiple things and it just... stopped.

http://pastebin.com/XVYpwUDQ

MisterTickle
03/06/2010, 05:30 PM
Okay I got it working but my issue now is for some reason their seems to always be a .jason created in my account folder (with no name as {} inside it) and a non .jason file in the script folder like... Just the file name would be Rebecca Sinclair, Nothing would save to it it would just sit there.

Why are all these random files cluttering my script files folder? Never had this problem with Dudb and I just changed it around so instead of returning dini functions it returned DJ functions so not much changed.

DracoBlue
03/06/2010, 09:08 PM
Can you provide the snippet which does the saving?

- Draco

MisterTickle
03/06/2010, 10:54 PM
DudB conversion include

http://pastebin.com/wERdJiMj

/register

http://pastebin.com/CUVtiDCH

Cedimedi
11/06/2010, 06:34 PM
Sorry if this allready got asked, but where exactly i can change the update time? I don't want it to update ever 1-3 seconds ;P

Zamaroht
11/06/2010, 07:52 PM
What do you mean with update? It updates the database cache every time a file gets readed/written, not every a specific amount of time.

Cedimedi
11/06/2010, 08:40 PM
lol, sorry, i was confused. I tought about dmap.. but found the solution :)

iggy1
13/06/2010, 02:24 PM
Hi im just trying to learn how to use djson and ran into a little problem (probably noob mistake) im just trying to count how many times a player connects and have this code, public OnPlayerConnect(playerid)
{
new string[30];
format(string,sizeof(string),"%s.json",playername(playerid));
djSetInt(string,"data/cons",djInt("users.json","data/cons")+1);
return 1; ^^^lol ^^^lol
}

I thought that would add 1 to "data/cons" everytime a player connects but it doesn't, no matter how many times a player connects its the same output, {"data":{"cons":1}}
I thought the second time a player connects it would read,{"data":{"cons":2}}
But it doesn't.
help please.

Do u think i should learn to use dini before djson? everone says this is the best file reader/writter about so i didn't want to learn dini first, but if thats the way forward i guess ill have to.

thanks in advance for help/advice

EDIT: Very stupid mistake u can probably see it straight away lol cant beleive i was that silly haha

DracoBlue
13/06/2010, 05:01 PM
Hi im just trying to learn how to use djson and ran into a little problem (probably noob mistake) im just trying to count how many times a player connects and have this code, public OnPlayerConnect(playerid)
{
new string[30];
format(string,sizeof(string),"%s.json",playername(playerid));
djSetInt(string,"data/cons",djInt("users.json","data/cons")+1);
return 1; ^^^lol ^^^lol
}

I thought that would add 1 to "data/cons" everytime a player connects but it doesn't, no matter how many times a player connects its the same output, {"data":{"cons":1}}
I thought the second time a player connects it would read,{"data":{"cons":2}}
But it doesn't.
help please.

Do u think i should learn to use dini before djson? everone says this is the best file reader/writter about so i didn't want to learn dini first, but if thats the way forward i guess ill have to.

thanks in advance for help/advice

EDIT: Very stupid mistake u can probably see it straight away lol cant beleive i was that silly haha

*smile*

But works now, doesn't it? ;)

Have fun coding,
Draco

iggy1
13/06/2010, 08:17 PM
Yes ofc it works ;) its my brain that doesn't haha. Was paniking earlier :D using it now exellent work btw.

iggy1
17/06/2010, 08:05 AM
Me again ;) hi is there something different i need to do with linux servers? i have ths code,
COMMAND:personalcar(playerid,params[])
{
new IsPlayerInAnInterior = GetPlayerInterior(playerid);
if(IsPlayerInAnInterior != 0) return SendClientMessage(playerid, red,"You Cant Use That Command In An Interior");
if(GetPlayerMoney(playerid) < Lprice)return SendClientMessage(playerid,GREEN,"You Don't Have Enough Cash That Costs $1000000!");
{
new String[50];
format(String,50,"Personalcar/%s.json",playername(playerid));
ShowPlayerDialog(playerid,6150,DIALOG_STYLE_LIST,"Personal Car","Cars \n Bikes","Select","Cancel");
GivePlayerMoney(playerid, - Lprice);
djSetInt(String,"personal/licence",1);//this wont save
}
return 1;
}
It works fine on windoze but the file wont save on linux :( any help much appreciated
thanks in advance.

BuLLeT[LTU]
17/06/2010, 10:47 AM
Is it working on linux? Because when i start server it turns off.

Lightning[SV]
17/06/2010, 11:32 AM
Me again ;) hi is there something different i need to do with linux servers? i have ths code,
COMMAND:personalcar(playerid,params[])
{
new IsPlayerInAnInterior = GetPlayerInterior(playerid);
if(IsPlayerInAnInterior != 0) return SendClientMessage(playerid, red,"You Cant Use That Command In An Interior");
if(GetPlayerMoney(playerid) < Lprice)return SendClientMessage(playerid,GREEN,"You Don't Have Enough Cash That Costs $1000000!");
{
new String[50];
format(String,50,"Personalcar/%s.json",playername(playerid));
ShowPlayerDialog(playerid,6150,DIALOG_STYLE_LIST,"Personal Car","Cars \n Bikes","Select","Cancel");
GivePlayerMoney(playerid, - Lprice);
djSetInt(String,"personal/licence",1);//this wont save
}
return 1;
}
It works fine on windoze but the file wont save on linux :( any help much appreciated
thanks in advance.


Linux is case sensitive so make sure the players file name is exactly the same as their username.

Btw, nice work Draco :)

iggy1
17/06/2010, 12:10 PM
]

Me again ;) hi is there something different i need to do with linux servers? i have ths code,
COMMAND:personalcar(playerid,params[])
{
new IsPlayerInAnInterior = GetPlayerInterior(playerid);
if(IsPlayerInAnInterior != 0) return SendClientMessage(playerid, red,"You Cant Use That Command In An Interior");
if(GetPlayerMoney(playerid) < Lprice)return SendClientMessage(playerid,GREEN,"You Don't Have Enough Cash That Costs $1000000!");
{
new String[50];
format(String,50,"Personalcar/%s.json",playername(playerid));
ShowPlayerDialog(playerid,6150,DIALOG_STYLE_LIST,"Personal Car","Cars \n Bikes","Select","Cancel");
GivePlayerMoney(playerid, - Lprice);
djSetInt(String,"personal/licence",1);//this wont save
}
return 1;
}
It works fine on windoze but the file wont save on linux :( any help much appreciated
thanks in advance.


Linux is case sensitive so make sure the players file name is exactly the same as their username.

Btw, nice work Draco :)


Lol silly me thanks m8 sorted. ;)