[solved] How do I find out size of a JSON database

Get help using Construct 2

Post » Sat Feb 21, 2015 5:49 pm

Hi,

Is it possible to find out the size of a JSON database?

Database
- 1: Price:50, Time:10
- 2: Price: 100, Time: 20
- 3: Price: 150, Time: 30
- 4: Price: 200, Time: 40

so I need the variable 4, but how? Anyone an idea, tip, hint?
Thx
You do not have the required permissions to view the files attached to this post.
Last edited by edwardr on Sun Feb 22, 2015 11:19 pm, edited 1 time in total.
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Sun Feb 22, 2015 2:01 am

Without using the "JSON plugin", you could create a dictionary object and add all the values you want there.
Then you will be able to retrieve any value just by knowing the name of the value you need.
Also, if you want to make a JSON string that includes all the dictionary, all you have to do is to text Dictionary.asJSON anywhere you want (for example inside a key in webstorage)

Take a look: https://www.scirra.com/manual/140/dictionary
B
11
S
3
G
1
Posts: 91
Reputation: 997

Post » Sun Feb 22, 2015 11:58 am

ok, I don't see which command could help me? I think there is also a little misunderstanding.
I'll explain what I need:

I have a text box which shows the actual e.g. research level. When you click the spirit, it goes to the next "level". Of course somewhen there is no next level and then "undefined" appears. This is not nice :(

I want to add a compare value in it, which says you can go to the next level until there is no one, which stops adding a additional level.

so something like that. compare level <= json maximum of this database. I don't want to add manually a global variable, which says this database has 4 Levels. C2 should do this automatically for me :)
You do not have the required permissions to view the files attached to this post.
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Sun Feb 22, 2015 10:35 pm

hahaha.... easier than thought..
there is a command database.size(0)
You do not have the required permissions to view the files attached to this post.
B
15
S
4
Posts: 77
Reputation: 1,030

Post » Sun Feb 22, 2015 11:30 pm

Excellent! :D
B
11
S
3
G
1
Posts: 91
Reputation: 997


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 23 guests