I've been implementing the delayed Character Creation method from https://github.com/ThePix/QuestJS/wiki/Character-Creation but I've hit a snag, it keeps wanting to repeat the settings.setup() step and my game is in an infinite loop and I can't see any items added to the Lounge room object or move anywhere because of the wait trigger in the setup.
settings.js
"use strict"
settings.title = "Your new game"
settings.author = "Your name"
settings.version = "0.1"
settings.thanks = []
settings.warnings = "No warnings have been set for this game."
settings.playMode = "dev"
settings.genders = [
{ name: "Male"},
{ name: "Female"},
{ name: "Non-binary"},
]
settings.setup = function () {
msg("This is the game intro")
wait()
trigger(function () {
document.getElementById('panes').style = "display: none"
settings.setUpDialog()
return true
})
}
settings.startingDialogEnabled = false
settings.startingDialogTitle = "Who are you?"
settings.startingDialogWidth = 500
settings.startingDialogHeight = 'auto'
settings.startingDialogButton = 'OK'
settings.startingDialogHtml = '<p>Name: <input id="CCName" type="text" value="Player" /></p>'
settings.startingDialogHtml += '<p>Species: <input id="CCSpecies" type="text" value="Human" /></p>'
settings.startingDialogHtml += '<p>Gender: <select id="CCGender">'
for (const s of settings.genders) {
settings.startingDialogHtml += '<option value="' + s.name + '">' + s.name + '</option>'
}
settings.startingDialogHtml += '</select></p>'
settings.startingDialogOnClick = function () {
player.setAlias(document.querySelector("#CCName").value)
player.species = document.querySelector("#CCSpecies").value
player.gender = document.querySelector("#CCGender").value
document.getElementById('panes').style = "display: block"
world.nodesc = false;
w.me.loc = "Lounge";
clearScreen()
endTurnUI()
}
settings.startingDialogInit = function () {
document.querySelector('#CCName').focus()
}
settings.startingDialogAlt = function () {
player.species = 'Human'
player.gender = 'Female'
player.setAlias('Velvet')
}
data.js
"use strict"
createItem("me", PLAYER(), {
loc:"Lounge",
synonyms:['me', 'myself'],
examine: "Just a regular guy.",
species: 'Human',
gender: 'Female',
genitals: 'Vagina'
})
createRoom("Lounge", {
desc: "The lounge is boring, the author really needs to put stuff in it.",
roomTemplate: [
"#{cap:}",
"{terse:{hereDesc}}",
"{objectsHere:You can see {objects} here.}",
"{exitsHere:You can go {exits}.}",
"{ifNot:settings:playMode:play:{ifExists:currentLocation:todo:{class:todo:{show:currentLocation:todo}}}}",
],
afterCreation: function (o) {
console.log("Lounge creation")
},
north: new Exit("Bedroom")
})
createItem("PlayerInfo", {
alias: "Player Info",
loc: "Lounge",
hereVerbs: ["Interact"],
examine: "A machine for displaying the player information and allowing it to be changed",
interact: function () {
//msg("<a href=\"javascript:void(0);\" onclick=\"displayPlayerInfo()\">Change?</a>")
},
})
createRoom("Bedroom", {
desc: "",
roomTemplate: [
"#{cap:}",
"{terse:{hereDesc}}",
"{objectsHere:You can see {objects} here.}",
"{exitsHere:You can go {exits}.}",
"{ifNot:settings:playMode:play:{ifExists:currentLocation:todo:{class:todo:{show:currentLocation:todo}}}}",
],
south: new Exit("Lounge"),
beforeEnter: function () {
clearScreen()
},
afterCreation: function (o) {
console.log("Bedroom creation")
}
})
The problem seems to be that you have settings.startingDialogEnabled = false
. If this were set to true, the world.begin()
function would exit immediately, instead of calling settings.setup()
again. As it is, when you click "OK", it calls world.begin()
, which calls settings.setup()
, and the process restarts.
To keep settings.startingDialogEnabled = false
, you can add this function to settings.js
. It's just the default function with world.begin()
commented out.
settings.setUpDialogClick = function() {
settings.startingDialogEnabled = false
io.enable()
settings.startingDialogOnClick()
//world.begin()
if (settings.textInput) { document.querySelector('#textbox').focus(); }
document.querySelector("#dialog").style.display = 'none'
}