Code troubleshooting

I am working on this bit to ask the user for a pass code for the smartphone, and then have them reconfirm it, then set the pass code

tempPassCode = null
phone_.locked = true
firsttime {
  if (phone_.switchedon =true) {
    msg ("Welcome to Chapel Perilous")
  }
  if (phone_.locked = true) {
    get input {
      msg ("The phone is locked")
      msg ("Please enter a 4 digit pass code as your          personal security for this device")
      msg (result)
      tempPassCode = result
      msg (tempPassCode)
    }
    msg ("Thank you for choosing a pass code")
    msg ("Please enter it again to confirm selection")
    get input {
      while (checkPassCode <> tempPassCode) {
        msg ("You have entered an incorrect pass          code,please try again")
        checkPassCode = result
      }
      tempPassCode = result
    }
    phone_.passCode = tempPassCode
    msg ("Your pass code is now " + phone_.passCode)
  }
}
otherwise {
  msg ("The phone is already on. Do you want to turn it  off?")
}```

The game kicks out this error
```Error running script: Only one 'get input' can be in progress at a time```

but as far as I can see, the brackets are closed so the get input statements should resolve.

Do I need to create several functions and then call each phase of this as a function?

or is my code just bad?

There are several msg segments used as debugging, and they are not getting called, the first get input is not starting.  it is skipping them.

thanks

"-" egoproctor

As I see it...
The problem is with Quest core programming...
IE: (in Quest)
msg(1)
msg(2)
msg(3)
msg("What is your name?")
get input {
msg("Hello, " + result)
}
msg(4)
msg(5)

You would expect:
1
2
3
What is your name?
(program stops and waits for your answer, and this is what MOST programming languages would do)
4
5

BUT, Quest does not stop on a get input, but will continue running, then come back to the get input.
IE:
1
2
3
4
5
What is your name?
(NOW, it stops for your answer...)

Want you need to do is nest the get inputs inside each other like this...
msg(1)
msg(2)
msg(3)
msg("What is your name")
get input {
msg("Hello, " + result)
msg(4)
msg(5)
}

OR...
msg(1)
msg("What is your name?")
get input{
msg("Hello, " + result)
msg ("So, where do you like to eat?")
get input {
msg("Yea, me too!")
msg(2)
msg(3)
}
}

If it were me programming Quest core... I would have the script stop on a get input, then continue after it...
Maybe someone could fix that for Quest 6.0...
BUT, that would mean it would no longer be compatible with pre-6.0 code,
AND, everyone would need to learn the change.


So, that means I need to put each get input into its own function, and have the function return a value into the calling script, and then do what I need to do.

function getPassCode (tempPassCode)
{
get input { tempPassCode = result}
return tempPassCode

}
function checkPassCode (tempPassCode, confirmPassCode)
{
 while ( confirmPassCode <> tempPassCode) 
{
  get input { confirmPassCode = result }
 return confirmPassCode
}
msg 1
msg 2
msg 3
tempPassCode = getPassCode (tempPassCode)
checkPassCode = confrimPassCode (tempPassCode, confirmPassCode)
// one more check
if (confirmPassCode = tempPassCode) {
  phone_.passCode = tempPassCode
}
else
{
msg 4
// loop again and check for bugs
}

will that get around the issue?


Because the error is that there is more than 1 active get input at the same time, so nesting them is the same problem, isn't it? if it is going to just run
1
2
3
4
5

then having a get input nested in a get input for 3 4 is still going to try to run both at the same time, yes?


tried putting the get input command in a function, and it didn't even make a call to it.

this is going to be like learning to take half of my brain out when I program,

How many more features of the Quest engine are as counter intuitive as this?

RTFI, except that means reading all the core code to find out what kind of obstacles are in between me as a coder and any given end user. haha. adventures in the matrix for sure. haha


It might be easier if you think of the get input statement's purpose as "Make a note of a script to run the next time the player types something".


There is a page in the docs about this, though it is easyto miss:
http://docs.textadventures.co.uk/quest/blocks_and_scripts.html


I just confirmed that get input DOES work with on ready. That is why, for one of my games, I put on ready at the start of all of my turnscripts.


ok. I will take a look at that documentation.

In the meantime, this is the fix I came up with after some sleep.

phone init script

this.tempPassCode = null
this.checkPassCode = null
this.passCode = null
this.switchedoff = true
this.locked = true

phone_ object switch on scipt

firsttime {
  if (phone_.locked = true) {
    msg ("please input a pass code")
    getPassCode
  }
}

the functions

getPassCode()

get input {
  phone_.tempPassCode = result
  msg ("thank you, you entered " + phone_.tempPassCode)
  msg ("Please enter your pass code again")
  getCheckCode
}

getCheckCode()

phone_.checkPassCode = null
get input {
  phone_.checkPassCode = result
  msg ("you entered " + phone_.checkPassCode)
  confirmPassCode
}

confirmPassCode()
if (phone_.checkPassCode <> phone_.tempPassCode) {
  msg ("Your pass codes do not match, please enter your pass code again")
  getCheckCode
}
else {
  phone_.passCode = phone_.tempPassCode
  msg ("Thank you for confirming your pass code")
  msg ("Please remember your pass code")
  msg ("It is " + phone_.passCode)
  msg ("You will need it as the journey continues")
}

When I was looking at errors, this statement by DarkLizard triggered memories of Q-Basic and goto statements, so I just programmed in that mode.

	
DarkLizerd  Jun 12, 2017 11:12 PM
I HATE that error message... Error running script: Object reference not set to an instance of an object.
It is the MOST unhelpful message!!!
(Other than the one I got so often in early BASIC... "Something is wrong"...)
But... One idea...
Typo...
or you are using a variable that you have not set a starting value...
IE:
player.hp=player.hp +1
but you forgot to tell Quest earlier...
player.hp=10

but I will experiment with other solutions.
thanks for the documentation.


and a successful test

turn on phone

You switch it on.
please input a pass code
thank you, you entered 4444
Please enter your pass code again
you entered 3333
Your pass codes do not match, please enter your pass code again
you entered 2222
Your pass codes do not match, please enter your pass code again
you entered 4444
Thank you for confirming your pass code
Please remember your pass code
It is 4444
You will need it as the journey continues

thanks again


the next question would be, making sure the character count is 4, and that they are all numeric.

I will look through the documentation for a string length attribute, if not, then I guess it is the old fashioned way.
I hope I can build an array, and then count through it if I need to.

And I should be able to confirm character entry data types, yes?


The quickest way to check for a code that's 4 digits is probably: if (IsRegexMatch("^\\d{4}$", result)) {; but that's not very clear. To be understandable, you'd want something like if (LengthOf(result) = 4 and IsInt(result)) {


resources:

http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)

http://docs.textadventures.co.uk/quest/functions/#string (string manipulation functions)


the 'get input' Function always returns (stored in the built-in 'result' local string variable) your input as a string data type/value, but you can then convert it into whatever data type you want, example below

get input {
  // I input (type in): 4
  msg ("Value Type: " + TypeOf (result))
  if (IsInt (result)) {
    result = ToInt (result)
    msg ("Variable (and Value) Type: " + TypeOf (result))
    msg ("Integer Value: " + result)
    result = result + 5
    msg ("Integer Value: " + result)
  } else {
    msg ("Error: Your inputed value is not an integer character-string type of input, for example, inputting: 'abc' ===> IsNumeric (XXX) = false)  / IsInt (XXX) = false / IsDouble (XXX) = false, VS, inputting: '4' ===> IsNumeric (XXX ) = true / IsInt (XXX) = true / IsDouble (XXX) = false")
  ]
}

// output/results:

Value Type: string
Variable (and Value) Type: int // or: integer // (whatever it is, meh, lol)
Integer Value: 9

data type conversions:

http://docs.textadventures.co.uk/quest/functions/getobject.html

http://docs.textadventures.co.uk/quest/functions/tostring.html
http://docs.textadventures.co.uk/quest/functions/toint.html
http://docs.textadventures.co.uk/quest/functions/todouble.html

create ("ball")

example_string_variable = ball.name // or: example_string_variable = ToString (ball) // or: example_string_variable = GetString (ball, "name")

example_object_reference_pointer_variable = GetObject (example_string_variable)

checking data types (type and/or existence):

http://docs.textadventures.co.uk/quest/functions/typeof.html

http://docs.textadventures.co.uk/quest/functions/hasattribute.html

http://docs.textadventures.co.uk/quest/functions/hasboolean.html
http://docs.textadventures.co.uk/quest/functions/hasdouble.html
http://docs.textadventures.co.uk/quest/functions/hasint.html
http://docs.textadventures.co.uk/quest/functions/hasobject.html
http://docs.textadventures.co.uk/quest/functions/hasscript.html
http://docs.textadventures.co.uk/quest/functions/hasstring.html

http://docs.textadventures.co.uk/quest/functions/string/isnumeric.html

http://docs.textadventures.co.uk/quest/functions/isint.html
http://docs.textadventures.co.uk/quest/functions/isdouble.html

http://docs.textadventures.co.uk/quest/functions/doesinherit.html


checking+getting an attribute's value (or of an Object):

(this also does the same as the 'has' functions too)

http://docs.textadventures.co.uk/quest/functions/getattribute.html

http://docs.textadventures.co.uk/quest/functions/getboolean.html
http://docs.textadventures.co.uk/quest/functions/getdouble.html
http://docs.textadventures.co.uk/quest/functions/getint.html
http://docs.textadventures.co.uk/quest/functions/getobject.html
http://docs.textadventures.co.uk/quest/functions/getstring.html


thank you hegmonkhan and mrangel.

Now it is time to play around and see what kind of system I can build.

I think my first attempt at this is going to be in a single room, just chasing information through the phone interface. then I can expand once that is polished.

Cheers.


Here is another problem I am looking to solve.

ShowYouTube ("3tzE98pQH08?start=30&end=50")

The start part of this works in the embedded code, but it does not end the video at the specified time. All numbers represent seconds.

You can copy and paste this link into your browser and see that the YouTube app or website will end the video at the specified second.

https://www.youtube.com/embed/3tzE98pQH08?start=30&end=50

I don't see anything in the core engine that will let me easily grab the YouTube video id and parse it for the start and end times to then create a time to stop the video with.

I also have the issue that the video will only play when the player clicks on the video.
The engine will load the video as embedded, but it won't automatically start the video for the player.

So, what I am looking for is:
A) a way to get the game engine to stop the playing of the video based on the end prompt in the id
or
B) a way to grab the start and end times, find the difference and then set a timer to play the video for only that long.
i) know when the player activates the YouTube video playback so the timer can start when the video starts.

any ideas?


I think KV's audio/video library should do what you want:

http://media.textadventures.co.uk/games/PHVys9dICUiMSSpr_m9WYQ/index.html


I got the end feature to work, funny work around

3tzE98pQH08?start=30&end=35&end=35

I have to send the end command twice, so there must be something filtering it out the first time. strange. that takes care of the first problem.

However, I can only use the web version of Quest as I am using a chromebook.


No, it's not being filtered out.

The code takes the id you pass and creates a URL of the form: "https://www.youtube.com/embed/" + id + "?autoplay=1&rel=0"

With your ID-and parameters, this will create the URL: "https://www.youtube.com/embed/3tzE98pQH08?start=30&end=35?autoplay=1&rel=0"
This passes 3 parameters to the player:

  • start with the value 30
  • end with the value "35?autoplay=1"
  • rel with the value 0

By adding a duplicate "end" parameter, only the second one gets mangled (and where an option is specified twice in a URL, the player takes the first one)

Your workaround works, but I think you could just as easily use something like 3tzE98pQH08?start=30&end=35&junk=a. It's not the second "end" that makes the difference; it's just that the last parameter on the line (and the automatically-added autoplay) is always mangled, so you're adding an extra one to the end that doesn't do anything.

An alternative fix would be to add this to your user interface initialisation script:


JS.eval("AddYouTube=function(id){addText($('"+Chr(60)+"iframe"+Chr(62)+"',{width:425,height:344,frameborder:0,allowfullscreen:'allowfullscreen',src:'https://www.youtube.com/embed/'+id+((id.search('\\?')>0)?'&':'?')+'rel=0'+((id.search('[?&]autoplay=')>0)?'':'&autoplay=1')}));};")

This should (assuming I'm typing correctly off the top of my head) fix the AddYouTube function so that it doesn't mangle the URI if you put parameters in the ID. It also allows you to specify "autoplay=0" to disable autoplay.


Thanks for the update.
I am going to have to research my regular expressions again, it has be about 6 years since I did any serious coding. Lived in China for 3 years and have been adventuring across America on a bicycle for last year. The 2 years in between I was researching comparative mythology and religion and physics and history, uncovering a lot of things that don't often get discussed. My mind has gotten filled with other information, use it or lose it. haha.

Looking for reasons why the autoplay doesn't autoplay even when set and it seems most browsers on desktop and mobile devices have settings that prevents autoplay videos from playing. It seems that parameter may soon become deprecated since most browsers are not going to support the feature, and finding where to allow autoplay in the settings isn't always clear.

and yes, I added a parameter after the end and it worked just like having an end parameter.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums