Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2016-06-04 19:12:26, last edited by MartenM (2016-06-04 20:02:48)

MartenM
Member
From: The Netherlands
Joined: 2016-03-31
Posts: 969
Website

Saving data

Hi there guys.

So just a month ago I think I started with making bots. I used tutorials for saving wins etc. Now I'm using the .ini files to save data.

Now here come's my problem. I feel like this is not the best way to save data. It's hard to loop through etc.

What method would you guys recommend for me.
As I'm still learning every day new things in C# something that would be a bit user friendly would be nice //forums.everybodyedits.com/img/smilies/smile

(Btw want to have the data saved on my own pc. Just in case someone comes with a server method.)
It's meant to save user data for my bot games.


lm3hgg8.jpg

Ingame: marten22        My steam: MartenM

Offline

#2 2016-06-04 19:28:15

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Saving data

I used just regular text files.


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#3 2016-06-04 19:44:29

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: Saving data

Use XML or text documents or why not, MySQL database.

Offline

#4 2016-06-04 19:50:58

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Saving data

^Do you have a suggestion on a tutorial for setting up SQL databases? I had an SQLite database (cuz idk why) and that was a pain... the updates were always the wrong version for the .NET framework... and I updated from NuGet vs. web download ugh all around.

If you want "user friendly," then the easiest thing you can do is a straight-to-textfile approach. Then you can see if your function is outputting right, etc. However, the next best thing would prolly be cap's SQL suggestion. Provided a good UI, all you'd need to figure out is the actual programming quirks involved.

But straight easiest, user-friendly approach is definitely text.

I used binary writer/reader back in the day. You can't really read those with your eyes... but they worked well enough once I figured it out.

Offline

#5 2016-06-04 19:54:01

Kikikan
Member
From: Hungary
Joined: 2015-08-10
Posts: 204

Re: Saving data

My vote goes for text files.
Use StringBuilder and the File class for that.

Offline

#6 2016-06-04 20:22:22

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Saving data

Why does everybody suggest MySQL? Isn't it a hassle? I tried to google some things about it and I couldn't find anything that would help me set one up - just to see what it would be like to have one


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#7 2016-06-04 20:32:14

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Saving data

Well, I like this discussion
stackoverflow look out kiddos

idk what to make of it. saving a file seems to make sense... but I suppose if we actually got to a lot of people, loading all 2000 (wishful thinking) players' data isn't as reasonable (on the RAM or whatever) as the 30 active, present folk.
For the most part, I probably had my DB poorly configured, because it always took too long to make a search, much longer than if I just loaded the data into memory.

Offline

#8 2016-06-04 20:33:02

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: Saving data

PROTOBUF.


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

Wooted by:

#9 2016-06-04 20:47:47, last edited by Tomahawk (2016-06-04 20:48:02)

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,830

Re: Saving data

MartenM wrote:

It's hard to loop through etc.

If you're not already using the 'File.ReadAllLines' method in System.IO, which reads all the lines into a string array, you should. It makes reading from the file incredibly easy, and from there you can loop through the array and split each line or whatever.

If you really think you have enough data to justify using a DB, I recommend SQL Compact Edition, which is well supported by VS and can store all your data in a single datatable (.sdf) file.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

Wooted by:

#10 2016-06-04 23:37:09

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Saving data

Couple suggestions also listing previous suggestions I find good:
Plain text file (I'd say is hardest as you have to give your own context to everything).
CSV file (Usually what people do when they write to plain text).
XML file (you have to make your objects serializable though, not hard, but you'd have to make a couple googles in how to do this. + side is you can save and load object directly through a single simple method you rip off the internet).
JSON file (basically same concept as XML. Makes your files some smaller, but for some people it's a bit harder to understand, again).
Database (I'd say Ms/Sql, I think visual studio can automatically create a local mssql database in your project, otherwise it's another sql language. Problem is you'd have to learn SQL and would still have to format it back into your own objects, but it's by far the strongest method).

Offline

#11 2016-06-06 02:32:22, last edited by Jabatheblob1 (2016-06-06 02:34:07)

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: Saving data

What i would always do(and did up until i became inactive on ee) was i would have a function to save each persons data. So let's say that you were making an rpg and wanted to save a person's HP, i would have a function just dedicated to HP, kinda like i had one for wins. I would have a function that would check wins and one that would add wins. Like for the digbot i had, i had so many functions that it made it easy when i was making aspects of the game, but it was a ton of code. I came up with a more efficient way later, but i would start there to make it easy.

If you just want to save data right then and there, you can make a dictionary with the key being the userid and the value being another dictionary, the key of that dictionary could be the thing you're searching for, for example, HP, you type the string 'HP' and that person's HP would then come up. You can save it when they leave(which isn't the best idea if your bot crashes a lot). But that's another approach you could take.


If you would like me to make a bot for you, go here.

Offline

Wooted by:

#12 2016-06-06 08:31:03

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Saving data

Jabatheblob1 wrote:

What i would always do(and did up until i became inactive on ee) was i would have a function to save each persons data. So let's say that you were making an rpg and wanted to save a person's HP, i would have a function just dedicated to HP, kinda like i had one for wins. I would have a function that would check wins and one that would add wins. Like for the digbot i had, i had so many functions that it made it easy when i was making aspects of the game, but it was a ton of code. I came up with a more efficient way later, but i would start there to make it easy.

If you just want to save data right then and there, you can make a dictionary with the key being the userid and the value being another dictionary, the key of that dictionary could be the thing you're searching for, for example, HP, you type the string 'HP' and that person's HP would then come up. You can save it when they leave(which isn't the best idea if your bot crashes a lot). But that's another approach you could take.

It's kinda dirty though how you have to push all stats of the player through when you only want his HP. Best you just use public fields, with optionally a private set.

Offline

#13 2016-06-06 13:09:23

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Saving data

^ so player["hummerz5"]["HP"]?
I mean, a dictionary probably is overhead compared to a (public field?) but it's pretty easy to manage, too...
except for when you go making new attributes that don't have values... then the whole NotFoundException or whatever

yeah carry on

Offline

#14 2016-06-06 16:19:16, last edited by den3107 (2016-06-06 16:21:05)

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Saving data

hummerz5 wrote:

^ so player["hummerz5"]["HP"]?
I mean, a dictionary probably is overhead compared to a (public field?) but it's pretty easy to manage, too...
except for when you go making new attributes that don't have values... then the whole NotFoundException or whatever

yeah carry on

Fields are basically variables, haven't found the exact differences though. But you'd declare them in the head of your class (so not in a method), and this would be an example:

public int HP { get; private set; } // note no ; at the end

The { get; private set; } are automatic properties, meaning the get (getting the value) is public, and the set (setting the value) is private.

// You can do:
int playerHP = player.HP
// But can't do:
player.HP = 5

You can only set the HP value from within the Player class/object itself.

And you don't take half an hour making all those get set methods.

Note: You CAN also just make a public variable, but this is generally bad practice.

EDIT: You can also do some other stuff with the get and set, but won't go into detail with them.

Offline

#15 2016-06-06 16:21:31

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: Saving data

I would likely use a NoSQL database, probably MongoDB or similar.


signature.png
*u stinky*

Offline

#16 2016-06-06 19:40:07

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: Saving data

i said the complete wrong thing, what i usually do is make a dictionary with just a userid and a playerclass. I do sometimes use nested dictionaries but not for player information, i used it for something that really isn't required here. But just making a single player class and loading it when a player joins and saving when a player leaves would work just fine. As long as your bot is simple enough to not crash all the time, and if it does crash, you can save your data every 5 minutes or so(a lot better than live).


If you would like me to make a bot for you, go here.

Offline

Wooted by: (2)

#17 2016-06-06 20:18:54, last edited by Xfrogman43 (2016-06-06 20:19:12)

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Saving data

den3107 wrote:

And you don't take half an hour making all those get set methods.

den3107 wrote:

public int HP { get; private set; }

Yeah, instead you do get PRIVATE set methods


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#18 2016-06-06 21:05:15

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,852

Re: Saving data

Jabatheblob1 wrote:

i said the complete wrong thing, what i usually do is make a dictionary with just a userid and a playerclass. I do sometimes use nested dictionaries but not for player information, i used it for something that really isn't required here. But just making a single player class and loading it when a player joins and saving when a player leaves would work just fine. As long as your bot is simple enough to not crash all the time, and if it does crash, you can save your data every 5 minutes or so(a lot better than live).

or, with the crashing:
add a soft landing... catch the error, save the data, then throw it for the IDE?

Offline

#19 2016-06-06 21:58:25

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: Saving data

Xfrogman43 wrote:
den3107 wrote:

And you don't take half an hour making all those get set methods.

den3107 wrote:

public int HP { get; private set; }

Yeah, instead you do get PRIVATE set methods

You can always remove the private and get a public set method, really that hard to figure out? Can also make the get private, but I just added the private to show it's possible.

Offline

Wooted by:

#20 2016-06-06 22:06:39

Jabatheblob1
Member
Joined: 2015-03-01
Posts: 856

Re: Saving data

hummerz5 wrote:
Jabatheblob1 wrote:

i said the complete wrong thing, what i usually do is make a dictionary with just a userid and a playerclass. I do sometimes use nested dictionaries but not for player information, i used it for something that really isn't required here. But just making a single player class and loading it when a player joins and saving when a player leaves would work just fine. As long as your bot is simple enough to not crash all the time, and if it does crash, you can save your data every 5 minutes or so(a lot better than live).

or, with the crashing:
add a soft landing... catch the error, save the data, then throw it for the IDE?

Yeah you can do that, i'm just suggesting simplified answers given he's asking how to save data. I don't know if that's too far for him or not.


If you would like me to make a bot for you, go here.

Offline

Wooted by:
Jabatheblob11465247199605277

Board footer

Powered by FluxBB

[ Started around 1713481172.3954 - Generated in 0.219 seconds, 10 queries executed - Memory usage: 1.69 MiB (Peak: 1.92 MiB) ]