Quest 6: Adding QUIT and RESTART commands

commands.push(new Cmd('MetaRestart', {
  regex:/^restart$/,
  script:function() {
    //NOTE:  This command is for everyone accustomed to INFOCOM and/or Inform games.
  
      askQuestion('Do you really want to restart the game? {b:[Y/N]}', function(result) {
      
      switch (result){
		case "Yes":
		case "yes":
		case "Y":
		case "y":
		case "YES":
		    location.reload();
		    break;
		case "No":
		case "no":
		case "N":
		case "n":
		case "NO":
			msg("Wise decision.  Game on!");
			break;
		default:
			msg("That wasn't a 'Yes' or a 'No'. So, the game continues!");
	  }
    });
  return;
  },
}));


commands.push(new Cmd('MetaQuit', {
  regex:/^quit$/,
  script:function() {
    //NOTE:  This command is for everyone accustomed to INFOCOM and/or Inform games.
  
      askQuestion('Do you really want to quit the game? {b:[Y/N]}', function(result) {
      
      switch (result){
		case "Yes":
		case "yes":
		case "Y":
		case "y":
		case "YES":
			//msg("<br>Turns taken: {game.turnCount}<br>Score: {game.score} out of a possible {game.maxScore}<br>");
			msg("THANKS FOR PLAYING!")
			msg("<input type=\"button\" style='color:white;background-color:black'\
			 value=\"CLICK HERE TO PLAY AGAIN!\" onClick=\"window.location.reload(true)\">");
		    io.finish();
		    break;
		case "No":
		case "no":
		case "N":
		case "n":
		case "NO":
			msg("Wise decision.  Game on!");
			break;
		default:
			msg("That wasn't a 'Yes' or a 'No'. So, the game continues!");
	  }
    });
  return;
  },
}));

My personal view is that there is a reload button in every browser to do this, so I will not be putting it into Quest 6.

However, a better way to check the result is with a regular expression.

commands.push(new Cmd('MetaRestart', {
  regex:/^restart$/,
  script:function() {
    //NOTE:  This command is for everyone accustomed to INFOCOM and/or Inform games.
  
    askQuestion('Do you really want to restart the game? {b:[Y/N]}', function(result) {
      if (result.match(/^(y|yes)$/i)) {
  	    location.reload()
      }
      else if (result.match(/^(n|no)$/i)) {
  		  msg("Wise decision.  Game on!");
      }
      else {
  	    msg("That wasn't a 'Yes' or a 'No'. So, the game continues!");
	    }
    });
    return world.SUCCESS_NO_TURNSCRIPTS;
  },
}))

Hello,

How do you make a button to call Restart Command (or other command) ? Exists it a function to call CMD ?

I don't sure how do that.

Thanks.

Best regards


Hello again!

I don't think Pixie has the command stuff set up in the Text Processor yet.

That being said, we could make our own links:

	var lnk = `<a href='javascript:void(0)' onclick='parser.quickCmd(findCmd("MetaRestart"))'>RESTART!</a>`
	msg(lnk)

...or buttons:

	var lnk = `<button href='javascript:void(0)' onclick='parser.quickCmd(findCmd("MetaRestart"))'>RESTART!</button>`
	msg(lnk)

Also:

//UPDATED 2020.12.08
commands.push(new Cmd('MetaRestart', {
  regex:/^restart$/,
  script:function() {
      var result = window.confirm("Do you really want to restart the game?")
      if (result) {
  	    location.reload()
      }
      else{
  		  msg("Wise decision.  Game on!");
      }
      return world.SUCCESS_NO_TURNSCRIPTS;
  },
}));

I don't think Pixie has the command stuff set up in the Text Processor yet.

Do you mean this?
https://github.com/ThePix/QuestJS/wiki/The-Text-Processor#commandcmd


I don't think Pixie has the command stuff set up in the Text Processor yet.

Do you mean this?

I get an error (and I don't think I fooled around with any code in my text.js, but I can't promise that).

Uncaught ReferenceError: link is not defined
    cmd file:///home/rh/Downloads/QuestJS-work_in_progress/lib/_text.js:417
    processText file:///home/rh/Downloads/QuestJS-work_in_progress/lib/_text.js:86
    processText file:///home/rh/Downloads/QuestJS-work_in_progress/lib/_text.js:30
    <anonymous> debugger eval code:1
debugger eval code:417:5

I'm looking into it after a bite to eat.


https://github.com/ThePix/QuestJS/blob/master/lib/_text.js#L425

I see io.cmd-link where it should be io.cmdlink.

Fixed that, and now the link isn't quite right.

So...

https://github.com/ThePix/QuestJS/blob/master/lib/_io.js#L754

Changed this . . .

io.cmdlink = function(command, str) {
  return '<a class="cmd-link" onclick="parser.parse(\'' + command + '\')">' + str + "</a>";
}


to:

io.cmdlink = function(command, str) {
  return `<a class="cmd-link" onclick="parser.parse('${command}')">${str}</a>`;
}

...and SUCCESS!


Finally I solved :

let savename = $("#savename").val();
parser.parse(`save ${savename}`;

Thanks to you, ThePixie and Richard Headkid ! :D


Log in to post a reply.

Support

Forums