What's the most efficient way of setting up a set of re-usable arrays of strings in a world script?
In randomshipnames 0.9 the names are constructed by calling a couple of nested functions. Each function defines a list of names and randomly returns one of them:
Code: Select all
this.$randomPirateName3b = function()
{
var name = ["Darkness", "Destruction", "Death", "Pain", "Torture", "Sorrow", "Tears", "Fear", "Fury", "Inferno", "Fate", "Despair", "Terror", "Horror", "Wrath", "Madness", "Rage", "Hellfire", "Storm", "Tragedy", "Misfortune", "Misery"];
return name[Math.floor(Math.random() * name.length)];
}
I suppose that this is the least efficient way of doing things, because the same functions are called for every single ship, so the same arrays have to be constructed again and again.
What I am currently doing is to set up my list arrays globally. Outside of any function I have a bunch of lists like this:
Code: Select all
this.randomMoneySingleName = ["Treasure", "Fortune", "Joker", "Aces", "Deuces", "Broadway", "Jackpot", "Surprise", "Prize", "Winner"];
Later I refer to them only by name.
My specific questions: What is the difference between using
this.
vs.
var randomMoneySingleName = [...]
?
What is the difference between doing it at the top of my script vs. doing it in the
startUp
handler?
And what is the difference between declaring the arrays like I do vs.
this.randomMoneySingleName = new Array(...)
or
var randomMoneySingleName = new Array(...)
?
In short: which of these is the most efficient for my purpose of creating a number of lists of ship name parts, and assembling names from these list whenever a ship is spawned? Which causes the least hiccup?