Blockland Forums > Modification Help

Making and reading a list easily

Pages: (1/2) > >>

Treynolds416:

How would I go about making a list of values that could be continuously added on to and read?

For example, I could type

/Set Treynolds416 dog
/Set (Other player) cat
/Set (Other player) mouse
/Set (Other player) human

then type

/WhatIs Treynolds416

And have the script return "dog"



Is there an easier way to do this without using FileIO?

otto-san:

script objects.


--- Code: ---new scriptObject(whatIs)
{
  value["cow"] = "moo";
};
function serverCmdWhatIs(%client , %1, %2, %3, %4, %5)
{
  if(whatIs.value[trim(%1 SPC %2 SPC %3 SPC %4 SPC %5)] !$= "")
    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)]);
}

function serverCmdSet(%client, %pl, %set)
{
  %pl = strReplace(%pl, "_", " ");
  if(%set !$= "")
    whatIs.value[%pl] = %set;
    messageClient(%client,'',"\c3You have set \c6"@%pl@"\c3 to \c6"@%set@"\c3.");
}
--- End code ---

untested, may not work

if you did /whatIs cow it would message you

cow is moo

edit:

if you want this list to save, you would have to use FileI/O.

lilboarder32:


--- Quote from: otto-san on April 10, 2011, 12:53:24 PM ---if you want this list to save, you would have to use FileI/O.

--- End quote ---
You are able to save objects and their values:
%obj.save(%filePath);


But if the any of the value names have spaces or special characters it would give syntax errors when re executing. So if that is the case you would need to use file objects and write the values to a text file manually.

otto-san:


--- Quote from: lilboarder32 on April 10, 2011, 03:36:02 PM ---You are able to save objects and their values:
%obj.save(%filePath);


But if the any of the value names have spaces or special characters it would give syntax errors when re executing. So if that is the case you would need to use file objects and write the values to a text file manually.

--- End quote ---
oh, right. I forgot about that.

Treynolds416:

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

Pages: (1/2) > >>

Go to full version