Thought I'd do my best to explain objects simply, and a few things of what you can do with them.
This Lesson One, focuses mainly on using text files with objects.
PHP Code:
// Lesson 1: Objects and How They Work
// Today we're going to make objects and use a few object functions!
// Objects must be created by making TStaticVars like below:
// temp.objName = new TStaticVar();
// Keep in mine, the capitalization in my var name is just a stylistic
// choice and has no effect on the outcome of the script. Tho, it's
// a good idea to make sure you've got all the capitalization correct
// when using TStaticVars() and things like it!
// Let's Begin!
function onCreated()
{
temp.newObj = new TStaticVar(); // Here we create the object.
// Below we will define some variables of the new object
// It being a created object, we can create as many vars
// as we want for the damn thing. :)
temp.newObj.personOne = "Stan";
temp.newObj.personTwo = "Zero";
temp.newObj.personThree = "Twinny";
temp.newObj.personFour = "James";
// With the newly created variables above, there are a number
// of things you can do with the information stored in each variable
// in the object.
// Let's look at a few!
// * - Files - * \\
// Here we will save the vars into a text file:
// temp.newObj.saveVars("textfilepath/textfilename.txt", 0);
// Keep in mind saveLines is another form of saving variables
// from objects into text files. However it saves each var line
// for line. I'm not too big on explanations right now as I don't
// use saveLines often.
// The first param for saveVars() is pretty obvious. :p
// The second param however, decides whether the file is overwritten,
// or merely if the file is just added onto!
// Having saved these informations into a text file, we can then later
// receive this information through a command we shall learn in the next
// lesson, dubbed: loadVars();
/* Special Practice Notes:
1. Things like saveVars(), or loadVars() are object only functions.
Meaning they can only be attached onto the tail of an object that
has, or in the case of loadVars sometimes, doesn't have information in it.
*/
}
// Lesson 1: Objects and How They Work, cont.
// Now that you understand the basics of objects and how you can understand the
// uses and storing of informations inside of them. Let's look a bit deeper
// our target for this lesson is loadVars.
// Now, when you first create an object, it usually has nothing in it.
// Of course that applies to IF you create the object first, but in my opinion,
// it's always best to clearly state out the new static variable assignment.
//Like before loadVars is am object only function, let's take a look at it's use.
function onStuff()
{
// Again we create the object.
temp.newObj = new TStaticVar();
// Now we load the vars from a text file, consider your test text file is named
// test.txt. And it contains the 5 names from before. We simply do this:
temp.newObj.loadVars("test.txt");
// But what if you wanted to get the information from an object through a script?
// We certainly can't just yank it out now can we? Of course not!
// There's only one sure shot thing that can get us the variables we want,
// and it's an object function! Aptly named, getDynamicVarNames().
// Dynamic variables are variables that never stay the same and could change
// at any time they or the person controlling them wishes for them to.
// Now the way to access the dynamic variables is a bit more difficult than the talk
// that's been going on around here. We're going to use a "for each" look,
// to go through the dynamic var names of an object.
// The for each loop allows us to apply a variable name to each piece of information
// in an array. So let's do something like this:
for (temp.oV: temp.newObj.getDynamicVarNames()) // In case you were wondering, getDynamicVarNames returns an array allowing for a for each loop to have it's way with the text file/
{
temp.someArray.add(temp.oV);
}
// We can now echo all the information from the dynamic variables in the object because
// the for each loop going through the values, added each value to "temp.someArray" one value
// at a time.
// Now that array contains all the information from the object. A simple way to echo all this info.
// to RC. Like so:
// echo(temp.someArray);
}