pmw57 wrote:Kaks wrote:There's just one problem with pmw57's approach: expandDescription collapses an array of alternative strings into just one string.
It does? Well that's news. Up until now I didn't realise that the descriptions were capable of random messages.
Well, yes, it does. Actually it's the whole point of having arrays in descriptions.plist. I thought we were there already. If I may remind you of your original question about Random Hits:
Commander McLane wrote:pmw57 wrote:The property list uses variables such as [random_hits_rocks_number2].
That's not a variable, but an entry in descriptions.plist (and yes, Random Hits uses
a lot of those for the randomized descriptions).
If you want its content in a JS script, use
expandDescription("[random_hits_rocks_number2]").
The
whole point of using an array named [random_hits_rocks_number2] in descriptions.plist is that when it is expanded (regardless whether by legacy or JS), one of the array-entries is randomly chosen by the engine.
How about something like this:
Code: Select all
this.descriptions['personalities-kaks-witchspace'] = [
"This should be interesting...",
"Oooh, shiny!",
"Ah, that's what it looks like!"
];
We can easily give arrays (all arrays) a random method that they can call on.
Code: Select all
Array.prototype.random = function () {
return this[Math.floor(Math.random() * this.length)];
};
So you can then show a random description with
Code: Select all
this.ship.commsMessage(this.description['personalities-kaks-witchspace'].random());
Yes, I know all that. My only question was specifically: How can I automatically
convert the array out of descriptions.plist into an JS-array. Or in other words: How do I get from this (entry in
descriptions.plist,
not in a
JS worldscript):
Code: Select all
"personalities-kaks-witchspace" = (
"This should be interesting...",
"Oooh, shiny!",
"Ah, that's what it looks like!"
);
to this:
Code: Select all
this.description = array['descriptions.plist entry personalities-kaks-witchspace, first subentry',
'descriptions.plist entry personalities-kaks-witchspace, second subentry',
'descriptions.plist entry personalities-kaks-witchspace, third subentry',
...,
'descriptions.plist entry personalities-kaks-witchspace, last subentry']
Perhaps I haven't made myself clear enough, so I try again:
I have a file named
descriptions.plist, containing a long list of strings in arrays,
for the very purpose of the engine choosing randomly one of those strings on certain occasions. I do not have
anything in a JS script. On the previous page Kaks mentioned that it is a lot of work for the engine to extract a string from the
descriptions.plist file, and it might be easier to convert all the arrays from
descriptions.plist to
JS arrays. My
one and only question to you guys was and is: How can that be done? I
do not want to rewrite the whole list manually. I am asking for a JS routine that would extract the content of
descriptions.plist automatically and put it in a list of JS arrays (or a three-dimensional JS-array, doesn't matter). I
do not want to know how JS chooses randomly content of an array, because I know that already. I only want to know how I
create the array in the first place,
without typing it into my worldscript, but only using the
existing descriptions.plist.
And the answer I extracted from the bits of information from you and Kaks in my last post here above is: Currently that isn't possible. Therefore my request to make it possible, perhaps by adding an optional parameter to expandDescription(), if that would work.
And now back to Random Hits, and sorry for the thread derailment.