Blockland Forums > Modification Help
Making and reading a list easily
Greek2me:
value["cow"] = "moo"; You're defining a field in the scriptObject "whatIs" called value[cow]. "whatIs.value[cow]" equals "moo".
whatIs.value[%pl] = %set; You're changing "whatIs.value[%pl]" to the value of %set. Let's say that %pl is "rat". That would mean that "whatIs.value[%pl]" is really "whatIs.value[rat]"
otto-san:
--- Quote from: Treynolds416 on April 11, 2011, 03:34:42 PM ---As you can probably infer, I haven't done any script objects to date. I will try to understand otto's script line by line:
--- Code: ---new scriptObject(whatIs) //Creates new script object under name of "whatIs"
{
============== value["cow"] = "moo"; //*For value "cow", set as "moo"*
};
function serverCmdWhatIs(%client , %1, %2, %3, %4, %5) //Sets up function and command with the client and 5 text arguments
{
if(whatIs.value[trim(%1 SPC %2 SPC %3 SPC %4 SPC %5)] !$= "") //If the stuff you just typed in isn't blank...
messageClient(%client,'',"\c6"@trim(%1 SPC %2 SPC %3 SPC %4 SPC %5)@"\c3 is \c6"@whatIs.value[trim(%1 SPC %2 SPC %3 SPC %4 SPC %5)]); //Send "(person) is (value)" to client
}
function serverCmdSet(%client, %pl, %set) //Sets up function with arguments for client, player, and value
{
%pl = strReplace(%pl, "_", " "); //Replace all underscores with regular spaces for player (Not sure why this is necessary but ok)
if(%set !$= "") //If you actually put something for the %set argument...
============== whatIs.value[%pl] = %set; //*Adds another value to the SO list*
messageClient(%client,'',"\c3You have set \c6"@%pl@"\c3 to \c6"@%set@"\c3."); //More messaging feedback
}
--- End code ---
All of the lines I don't fully understand have a bunch of equal signs next to them
--- End quote ---
i'll explain then
-value["cow"] = "moo"; --When the script object is made, a variable by default exists inside of it. In the SO, variables are stored in 'arrays' but they aren't really arrays at all.
VARIABLE[NUMBER/STRING] = VALUE;
This is used to be able to access the variables by another variable like so:
whatIs.value[%pl] = %set;
In this, whatever the user defined (%pl) is in "NUMBER/STRING" and "VALUE" is the user defined value (%set).
Basically, it works this way:
the script object stores data in "value" and whatever is in the brackets works as a label for the value of it. if "cow" is in the brackets, and "moo" is the value, then if you try to get the value of "value["cow"]" it will tell you it's "moo". if you try to get the value of "value" it will do nothing. if you try to get the value of "value["moo"]" it will do nothing because nothing with the label "moo" has been defined.
This is as best as I can explain it.
Treynolds416:
Thanks, that makes a lot of sense.
I wont lock the topic, but I've got all of the information I need