A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Data Persistence Explained

Go down 
AuthorMessage
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: Data Persistence Explained   June 24th 2011, 10:41 am

Important modules (called functions by some) you need to know:

Player:WaitForDataReady()
pcall(function() end)
Player:SaveBoolean(String key, Boolean value)
Player:SaveString(String key, String value)
Player:SaveNumber(String key, Number value)
Player:SaveInstace(String key, Instance value)
Player:LoadBoolean(String key)
Player:LoadString(String key)
Player:LoadNumber(String key)
Player:LoadInstace(String key)

What's all this about LoadInstances, WaitForDataReady, pcalls? Okay, I'll try to explain it. I'll start with the basics. A Player can recieve data that can be recalled later (even on a different server, although not on a different game) using a Load. To save data, first you need to get to the Player you want to save to. Then you use the appropriate Save function to save your data. Then replace String key with the name under which the data will be saved. Remember, this is a string value, so it needs "" even if its a name made up of numbers. Next, replace the other value with the type of data your saving. Let's say you're trying to save a true or false statement under the name "Bool". This is how it should look:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:SaveBoolean("Bool", true)
Technically speaking, this previous code would not work, so don't try. First, when the game first starts, "player" won't be ready to save data yet. That's where WaitForDataReady comes in. This waits until the player is ready before it continues the script. Usually soon after a player gets into the game, he's ready to recieve data. So here's our new script:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:WaitForDataReady()
player:SaveBoolean("Bool", true)
So is the script ready yet? Not quite. There's still a problem. What if for some reason, the Save didn't work? The script would crash, right? What we need is a way to decide if the code executed or not, then display a error message if it didn't... The answer is pcall! pcall is a protected call, it's also the only way a Save or Load will run. You could just say pcall(function() player:SaveBoolean("Bool", true) end), but that isn't very effective. It still has no way of telling the user a problem occured until it's too late. Why not use a if not pcall() then end? This says basically, if I can't do this pcall, then do this. Using this knowledge, I'd use this script:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:WaitForDataReady()
if not pcall(function() player:SaveBoolean("Bool", true) end) then
  print("Oopsy, the save made a mistake.")
end
Great, the script works now, right? Wait a moment, there's no way of retrieving the data! Load works the same as save except you need to know only the string name and it returns something. The best way to use it is to declare it as a variable. The final code will show you what I mean:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:WaitForDataReady()
if not pcall(function() player:SaveBoolean("Bool", true) end) then
  print("Oopsy, the save made a mistake.")
end
if not pcall(function() bool = player:LoadBoolean("Bool") end) then
  bool = false
  print("The 'Bool' value doesn't exist!  Defaulting!")
end
print(bool)


For Advanced Scripters:
I've used these techniques to build a saving text editor. I hope ROBLOX's next invention will be saving to the game, not just to players.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Data Persistence Explained   June 24th 2011, 11:56 am

They really should allow saving to the game. It would open many doors that I'd like open.
Back to top Go down
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: Re: Data Persistence Explained   June 24th 2011, 2:07 pm

I'd agree. I'd suppose the only option is a dedicated user for saving that rejoins the server every 40 minutes.... Did you check my Building Intermediate Tutorial: NXT Building?
Back to top Go down
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: Re: Data Persistence Explained   June 24th 2011, 2:14 pm

Wait a minute, sudden lightbulb, they don't because of VIRUSES!!!
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Data Persistence Explained   June 24th 2011, 9:19 pm

duuuh. XD
Back to top Go down
http://hackthissite.org
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: Re: Data Persistence Explained   June 25th 2011, 7:51 pm

Thanks for pointing out my stupidity...
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Data Persistence Explained   June 28th 2011, 10:07 am

That's why the owner should get an anti virus if he really cares.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 19

PostSubject: Re: Data Persistence Explained   February 4th 2012, 8:10 am

or they should just remove free models entirely...

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: Data Persistence Explained   

Back to top Go down
 
Data Persistence Explained
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Advanced-
Jump to: