Currently enhancing my Javascript skills by developing small text RPG games using HTML pages :) It's great practice, as I'm constantly seeking to expand my knowledge and improve the code in my projects.
At the moment, one of my goals is to implement language functionality into my project through a function;
language.addLang = function(name,id){
if (id != this.log[id]) {
this[name] = new Object;
this.log[id] = name
}
}
An edit: I want to check if I can compare an array index number with an argument id number. The 'name' in the argument represents the language name, like English with a string value. And the 'id' signifies which index of the array it will occupy. It also includes a conditional statement that will translate all text into that language for future use.
For those curious about what 'log' denotes;
language.log = [
undefined, 'English','Swedish','Japanese','German'
]
To sum up; As mentioned above, the length of the log array is currently 5. For instance, if I wish to add a new language to my project for translation purposes, I can call language.addLang('Chinese',5). This action will insert the string 'Chinese' into the array at index number 5. However, trying to add it to an existing index will result in an error instead of replacing 'Chinese' with another language.
I hope this clarification provides better insight compared to my previous post. While I can manually translate the content instead of creating a new object for each language, it would be incredibly useful to be able to compare the argument number with the index number.