Convert player input into Numeric Values?

erekerendo
I'm trying to allow the player to pick their age. However, this is proving a lot more difficult than I'd thought it would be. I want to limit ages to 16 or older.

I am suspicious that when I use "get input", it is recording the input as a letter rather than a number, causing the "object counter" script to automatically mark any value as less than 16.

Also, I'm also concerned with what to do if the player spells a number "sixteen" instead of puts it as a digit "16"

Any help or examples would be appreciated. Thanks

The Pixie
Use the ToInt function to convert "16" to 16 (get input will return a string). You would have to then test if it was over 16, and use recursion to ask the question again if not.

Is that enough to get you going?

HegemonKhan
Edit: fixed up my mistake in one of the code lines

-----------------

yes, 'get input' sets the input to be a String ("text"). you got to convert the String input into an Integer (int), and then store that (now) Integer input into an Integer Attribute. actually, quest may be able to do the parsing for you (you may not need to convert it into an integer yourself).

anyways, here's a code example for what you want:

<object name="player">
<attr name="age_integer" type="int">0</attr> // this is the same as... *
</object>

// * within the GUI~Editor:
// 'player' Player Object -> 'Attributes' Tab -> Attributes (the bottom box, I believe) -> Add -> (see below)
// (Object Name: player)
// Attribute Name: age_integer // if you prefer, you can label-name it just as 'age' for example (also note that quest IS case-sensitive: age =/= AGE), but then everywhere you'd have to use 'age', and not 'age_integer', which is just how I personally like to label-name things, as for example, it allows for me to have another Attribute 'age_string', a String Attribute, to hold string values such as "baby", "child", "teen", or "adult", .... (develop your own convention/system for labeling/naming as quickly as you can!), as remember that names MUST be unique, as the 'name' String Attribute is the way quest 'IDs' them.
// Attribute Type: int
// Attribute Value: 0

<function name="age_integer_function">
msg ("What is your age?")
get input {
if (IsInt (result) and ToInt (result) >= 16) { // checks if your inputted value is an Integer (a non-decimal number) and also then checks if the person typed in a number 16 or greater. Both conditions must be true, else they're prompted to input again (see further down for this looping).
player.age_integer = ToInt (result) // converts your input into an Integer and stores it into the 'player' Player Object's 'age_integer' Attribute (which has to be created/added as an Integer Type Attribute, if you've used the GUI~Editor to create/add this Attribute for your 'player' Player Object)
} else {
msg ("wrong input, try again, make sure you input an integer number and that it is 16 or greater.")
wait {
ClearScreen
age_integer_function // in code, the name of the function calls/activates the function and thus loops/repeats the function, requiring the person to input again. In the GUI~Editor, you find the 'add new script' that is the 'call function' Script, and just type in the small rectangle the name of the function that you wish to call/activate (you can ignore the adding of parameters for the time being, if you don't know how functions and parameters work).
}
}
}
</function>


-----------

to explain how to do this through the GUI~Editor, will take much more time... which I don't have at the moment (lots of school work to get done, grr)

HegemonKhan
here's a few links for you too:

http://docs.textadventures.co.uk/quest/ (main page of quest documentation web-pages/site)
http://docs.textadventures.co.uk/quest/guides/ (guides)
http://docs.textadventures.co.uk/quest/ ... ation.html (character creation guide)

"Quest Bible" Links:

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

Attribute Types:

http://docs.textadventures.co.uk/quest/types/

Elements (the main things in quest: Objects, Functions, Verbs, Commands, Exits, Turnscripts, Timers, Object Types, etc etc etc):

http://docs.textadventures.co.uk/quest/elements/

an Object's Attributes:

http://docs.textadventures.co.uk/quest/ ... bject.html

-------

ask if you need help or explanation of anything

erekerendo
Error running script: Error compiling expression 'IsInt and ToInt (result) >= 16': Unknown object or variable 'IsInt'

What did I do wrong now???

erekerendo
Lol. i fixed it using the monkey on a typewriter method.

HegemonKhan
oops.... my bad...

I forgot the condition: (result), for the 'IsInt'...

it should be this:

get input {
if (IsInt (result) and ToInt (result) >= 16) {
// whatever scripts
}
}


this was my mess up, sorry about that!

-------------

more explanation details (if interested) of what/why/how the scripting (didn't work: error) and does (if I had it coded right) work:

I left off the '(result)' for the 'IsInt' :

if (IsInt and ToInt (result) >= 16)

when it should ahve been:

if (IsInt (result) and ToInt (result) >= 16)

'result' is what 'IsInt' is checking... so thus the error, as it needs something to check in order to be able do the checking (lol), due to me forgetting to code the first '(result)' into the if script in my post, again sorry about that.

----------------------

CODING/PROGRAMMING requires ZERO typos! You have to be a flawless-perfect grammer-typo-spelling nazi! It makes you into a very good proof-reader/editor!

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

Support

Forums