Switch between text input field and just a cursor during play [SOLVED]

K.V.
15 Dec 2017, 00:30

I want it to switch from the default command box to the alternate prompt with cursor during play.

This is the best I've come up with, but it isn't quite the same as it is when you select the option in the editor.

//Switch to cursor prompt
JS.eval ("$('#txtCommandPrompt').html('" + game.commandcursor + "');setInterfaceString('TypeHereLabel', '');")

//Switch to text input box

JS.eval ("$('#txtCommandPrompt').empty().hide();setInterfaceString('TypeHereLabel', 'Type here...');")

I've changed the values of game.borderlesscursor and game.showcommandbar, but neither appears to have any effect (and it also appears that the former is set to false while the latter is true, whether I select 'use a cursor instead' or not).


This one is kicking my butt.


Forgewright
15 Dec 2017, 01:39

I saw this earlier, may contain clues/help. or not. It's all above my pay grade. just looks similar. Ar Ar
http://textadventures.co.uk/forum/quest/topic/5754/initinterface-help-required


K.V.
15 Dec 2017, 02:06

Eureka!

Forgewright, you the man!


K.V.
15 Dec 2017, 02:19

Here's what I used:

Logging into the computer:

ClearScreen
JS.eval ("$('#txtCommandPrompt').prepend('" + game.commandcursor + "');setInterfaceString('TypeHereLabel', '');")
JS.eval ("$('#txtCommandDiv').css('border','none');$('#txtCommand').css('outline','none').css('border', 'none');")

After logging out:

JS.eval ("$('#txtCommandPrompt').empty().hide();setInterfaceString('TypeHereLabel', 'Type here...');")
JS.setCommandBarStyle (game.commandbarformat)
JS.eval ("$('#txtCommand').css('font-family','"+game.defaultfont+"');")

Forgewright
15 Dec 2017, 03:11

Glad it worked out for you! I compare my forum searching skills to that of the proverbial blind squirrel...


K.V.
15 Dec 2017, 03:57

I compare my forum searching skills to that of the proverbial blind squirrel...

Me too.


Look!

Here's a bonus prize!

I just figured out how to make the player jump (or whatever we want the player to do).

It adds it to the command prompt first, as if the player had pasted it in, then it executes by simulating pressing ENTER in 1.5 seconds.

JS.eval (";document.getElementById('txtCommand').value = 'jump';var e = jQuery.Event('keypress');e.which = 13;e.keyCode = 13;setTimeout(function(){commandKey(e);},1500);")

K.V.
15 Dec 2017, 04:31

Here it is in slow motion:

JS.eval("var cmdFun = ['','j','u','m','p'];var i = 0;function iterateCmdFun(){if(i == cmdFun.length){var e = jQuery.Event('keypress');e.which = 13;e.keyCode = 13;commandKey(e);return false;}setTimeout(function(){document.getElementById('txtCommand').value = document.getElementById('txtCommand').value + cmdFun[i];i++;iterateCmdFun();},1500);};iterateCmdFun();")

Forgewright
15 Dec 2017, 04:41

Isn't that what the typewriter option at the bottom of the add script popup box does...?


K.V.
15 Dec 2017, 04:54

Kinda, but this puts it in the command prompt, one letter at a time, as if the player were entering the command. Then it simulates an ENTER press at the last letter, sending the command through.


Forgewright
15 Dec 2017, 07:09

Ahh, ghost writer.


Doctor Agon
15 Dec 2017, 08:10

In a previous thread on the forum, I seem to remember someone wanted to change the continue function. Wanted to restrict it to a certain letter as opposed to any key.
Could your 'keyCode/commandKey' help with that.


K.V.
15 Dec 2017, 14:11

Maybe... I'll try it out in a bit.


K.V.
15 Dec 2017, 15:59

How about this?

EDITED (added the function: WaitFunction(letter))

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Continue Function">
    <gameid>176bc4ca-f00d-456f-bfc9-b90bf4452749</gameid>
    <version>1.1</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <description type="string"></description>
    <enter type="script">
      WaitFunction ("g")
    </enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="WaitFunction" parameters="key"><![CDATA[
    key = UCase(key)
    key = Asc(key)
    if (key<Asc("A") or key>Asc("Z")) {
      error ("The key must be a letter!")
    }
    // DEBUGGING
    // msg(key)
    msg ("<div style='display:none' id='pressToContinue'><center><h4>PRESS "+Chr(key)+" TO CONTINUE!</h4></center></div>")
    JS.eval ("$('#pressToContinue').insertBefore($('#txtCommand')).css('display','block');setInterfaceString('TypeHereLabel','Press "+Chr(key)+" to continue!');$('input').bind('keyup',function(e){var value = (e.keyCode);if(value !== parseInt('"+key+"')){document.getElementById('txtCommand').value = '';setInterfaceString('TypeHereLabel','You must press "+Chr(key)+"');}else{	$('input').unbind('keyup');	setInterfaceString('TypeHereLabel','Type here...');$('#pressToContinue').hide();document.getElementById('txtCommand').value = '';}});")
  ]]></function>
</asl>

I've got it calling the function in the room's After enter script, just in case anyone want to play with this and change it around.

Just be sure to wrap your letter in "" in the parameter, just like you would any other string.

Example:

WaitFunction("c")