Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converter issue for variables/objects/rooms with spaces in their name. #102

Open
FloridaChristopher opened this issue Oct 27, 2024 · 7 comments

Comments

@FloridaChristopher
Copy link
Contributor

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.

@KVonGit
Copy link
Contributor

KVonGit commented Nov 22, 2024

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 names1, 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.

Footnotes

  1. Quest 5 will not allow spaces in variable names, though.

@FloridaChristopher
Copy link
Contributor Author

Well I guess I should look into at how Quest 5 handles that, we could probably copy their solution.

@KVonGit
Copy link
Contributor

KVonGit commented Nov 23, 2024

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.

QuestJS/lib/_io.js

Lines 1404 to 1428 in f9680fb

io.clickItem = function(itemName) {
if (io.disableLevel) return
if (!itemName) return
const o = w[itemName]
if (o.sidebarButtonVerb) {
runCmd(o.sidebarButtonVerb + ' ' + w[itemName].alias)
return
}
if (io.disableLevel) return;
// duplicated items would toggle twice
const uniq = [...new Set(io.currentItemList)];
for (let item of uniq) {
for (const el of document.querySelectorAll('.' + item + '-actions')) {
if (item === itemName) {
el.style.display = el.style.display === 'none' ? 'block' : 'none'
}
else {
el.style.display = 'none'
}
}
}
};


This bit specifically will have issues with spaces:

for (const el of document.querySelectorAll('.' + item + '-actions')) {


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.

@KVonGit
Copy link
Contributor

KVonGit commented Nov 23, 2024

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 Burger to Fred_Fred_Burger (and hope that isn't in-game text!)

@FloridaChristopher
Copy link
Contributor Author

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.

@ThePix
Copy link
Owner

ThePix commented Dec 6, 2024

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.

@FloridaChristopher
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants