Converter issue for variables/objects/rooms with spaces in their name.
Now this is basically entirely my fault for daring to use spaces in my variable/object names, but the current converter doesn't work with these sorts of variables.
I remember @ThePix saying there was no work-around for this quite a few times, when he was just trying to make it work for the sake of seeing if he could make it work.
Quest 5 will allow spaces in object names[^1], so he was trying to get things to work as similarly as possible (to an extent).
JavaScript simply won't allow this, though, and the code we use to create QuestJS games is pure JS.
[^1]: Quest 5 will not allow spaces in variable names, though.
Well I guess I should look into at how Quest 5 handles that, we could probably copy their solution.
I was completely mistaken. JavaScript will allow spaces in object names.
I think Pixie maybe disallowed spaces due to things like hyper-links(?).
Anyway, I commented out this one line, and it let me create an object with spaces in the name. I can type to interact with it, but the link in the menu doesn't work.
function createObject(name, listOfHashes) {
if (world.isCreated && !settings.saveDisabled) return errormsg("Attempting to use createObject with `" + name + "` after set up. To ensure games save properly you should use cloneObject to create ites during play.")
//if (/\W/.test(name)) return errormsg("Attempting to use the prohibited name `" + name + "`; a name can only include letters and digits - no spaces or accented characters. Use the 'alias' attribute to give an item a name with other characters.")
if (w[name]) return errormsg("Attempting to use the name `" + name + "` when there is already an item with that name in the world.")
if (typeof listOfHashes.unshift !== 'function') return errormsg("The list of hashes for `" + name + "` is not what I was expecting. Maybe you meant to use createItem or createRoom?")
Here is the code from the button:
<p class="item" onclick="io.clickItem('Fred Fred Burger')">Fred Fred Burger</p>
There is another object in the game with no spaces in its name, and here is its button:
<p class="item" onclick="io.clickItem('Bob')">Bob</p>
So, it looks like io.clickItem() is funny about spaces, maybe?
Let's find the code.
https://github.com/ThePix/QuestJS/blob/f9680fb53365b0b79583d1cdb67e4e345a622605/lib/_io.js#L1404-L1428
This bit specifically will have issues with spaces:
https://github.com/ThePix/QuestJS/blob/f9680fb53365b0b79583d1cdb67e4e345a622605/lib/_io.js#L1419
That would make JS look for HTML elements with the class .Fred Fred Burger-actions, and HTML classes don't work that way. Example: <p class="Fred Fred Burger-actions"/>Fred Fred Burger</p>
That would create 2 classes in actuality: Fred and Burger-actions. (That's just how HTML works, to my knowledge, which admittedly could be expanded, hehehe.)
So, how could this be handled in a way that would work across the board for most authors? It seems the most efficient approach would be to disallow spaces in names, but allow spaces in the alias.
createItem("Fred_Fred_Burger", {
loc:"lounge",
alias: "Fred Fred Burger",
synonyms:['fred'],
examine: "He looks a little nervous."
})
That works, and the one simple naming rule is: a name can only include letters and digits - no spaces or accented characters. Use the 'alias' attribute to give an item a name with other characters.
Any other solution would involve altering the name to replace the spaces with some other character to be removed again during other functions. So, if we were to replace spaces with _ for the class name to make things work, then we'd have to remove _ to actually find the object when clicking. ...but that would mean we couldn't use object names with _.
So, I bet the ThePix foresaw all of this and just declared no spaces or accented characters. Use an alias attribute. Boom. Handled.
I got lost in finding out why no spaces were allowed in QuestJS and lost track... You are talking about converting games with names with spaces. Sorry about that, haha. I was still mostly on-topic, though. I just dropped the ball at the end.
I need to look at the converter's code, but I'd think it could simply change object names' spaces into _ and create an alias with the name in those instances.
But what if that overwrote an actual existing alias?
This is another thing I bet ThePix already pondered, and that's why the converter isn't considered fully functional.
Hmm... I don't know... I guess it could:
- check for spaces
- if spaces exist
- if object has no alias, create alias from name
- else if object has alias, do nothing with alias
- replace spaces with
_ - replace all instances in the game's text like
Fred Fred BurgertoFred_Fred_Burger(and hope that isn't in-game text!)
- if spaces exist
Yeah that was what I was thinking. I might take a crack at it tbh. But I've never contributed to OSS before so idk how hard it's going to be.
I have to admit I wrote this first-and-foremost for my own benefit, and I never gave Quest objects names with spaces, but to a coder it just looks wrong. So not allow names with spaces was not a problem.
"But what if that overwrote an actual existing alias?"
I would suggest a check at the end of the process, and if there are two objects with the same name, just give a warning. It will be hassle for the user to sort out, but not that much, and it will be exceptional cases.
I think we should add a link in the converter page to the wiki page on the converter, it talks about things like this so it would probably clear up a lot of confusion.