Random code doesn't work

Melarnos
15 Jul 2016, 18:27

Hi everyone,

I'm trying to implement a random code, that can be used later in the game. It seems quite simple... but it doesn't work.
I found what seemed to be the exact answer to what I'm trying to do (check the second part of the page):
http://docs.textadventures.co.uk/quest/guides/unlockdoor.html

... actually that's what I was doing, but whereas this script works :
game.code = GetRandomInt (1000, 9999)

...this one doesn't :
result=game.code

I'm getting this message:
Error running script: Error compiling expression 'result=game.code': CompareElement: Operation 'Equal' is not defined for types 'String' and 'Int32'

So I guess :

  1. The documentation page is for a previous version of Quest
  2. "result=" should be followed by a number, not a variable

I tried to modify the code by integrating functions (IsInt, GetInt, ToInt...) to call the Integer value of the variable, but I guess I'm doing it wrong, I keep getting error messages.

What would be the correct way to do it?

Thanks!


The Pixie
15 Jul 2016, 19:03

That is an error in the documentation. What the player types is a string, which is the contents of "result". But game.code is a number (an int). As you seem to have realised, all you need to do is convert one to the other, eg, the player's input to a number:

ToInt(result)=game.code

Melarnos
15 Jul 2016, 19:15

It makes perfect sense :)
I put all my efforts in understanding why the function was not working with game.code... when it was "result" that needed to be converted into a integer. I'm such a noob :)
Thanks a lot!