## Checking for Integer and between.

In my text adventure, there is a gambling minigame where the min. bet is \$1 and max. bet is \$200 and the player needs to type in how much they want to bet, the variable I set up for that is player.wager.
The thing is, I don't know how to get the game to check if what they typed in WAS an integer in the first place or if it's between those two numbers. I'd also need to run a check to see if they have that much money in the first place.

How would I do all this?

Hi Gage, forgive me if this is not in script form, typing it on the fly. I'm assuming you've got a money variable as well that keeps track of how much money the player has eg. player.money.

``````If player.wager<1 or player.wager>200 then \\print a message "that is not a bet I can handle" or similar script
else if
\\check if the money the player has is less than the amount they want to bet
player.money<player.wager then print "you don't have the money to cover that bet"
else
\\take the money, reduce player.money by player.wager
player.money=player.money-player.wager
print "money taken. good luck"
``````

What might be better is having the maximum bet equalling what the player has to spend then checking against that.

``````betlimit=player.money
if betlimit>200 then betlimit=200
print "You can bet between \$1 and \$" + betlimit + "."
Get Input
if player.wager<1 or player.wager>betlimit then \\rest of script
``````

As I've said this is not in code so please forgive me. Hope it helps

So I tried to put into code what you said, and I got this error when testing the "betting outside the limits"
Error running script: Error compiling expression 'player.wager < 1 or player.wager > 200': CompareElement: Operation 'LessThan' is not defined for types 'String' and 'Int32'

THEN, when I tried betting again, I got another error:
Error running script: Error compiling expression 'player.wager = 0': CompareElement: Operation 'Equal' is not defined for types 'String' and 'Int32'

For the record, my script for the event looks like this :

if (player.wager = 0) {
msg ("Minimum starting amount you can insert in the slot is \$1.
Maximum starting amount is \$200.
get input {
player.wager = result
if (player.wager < 1 or player.wager > 200) {
msg ("That isn't a valid amount. Please use your wallet again and enter the right amount.")
player.wager = 0
}
else {
if (player.wager > player.cash) {
msg ("You can't bet more than you have. Please use your wallet again and enter the right amount.")
player.wager = 0
}
else {
msg ("You put in {player.wager} bucks, and wonder if tonight will be your lucky night.")
}
}
}
}
else {
msg ("You already put a bet in. To put in a different bet, push the "CASH OUT" button
and use your wallet on the slot again.")
}

Hello.

My code is a little different from yours, but it may help.

## EDITED (Twice)

Bet command script

Pattern:
`wager #text#;bet #text#`

``````firsttime {
game.minbet = 1
game.maxbet = 100
player.wager = 0
}
if (not player.wager = 0) {
msg ("You've already placed a wager.")
return(false)
}
if (IsInt(text)) {
wager = ToInt(text)
if (wager<game.minbet) {
msg ("You have to wager at least \$"+game.minbet+".  Please try again.")
return (false)
}
if (wager>game.pov.money) {
msg ("You don't have that much money.  Please try again.")
return (false)
}
if (wager>game.maxbet) {
msg ("The maximum wager is \$"+game.maxbet+".  Please try again.")
return (false)
}
player.wager = wager
msg ("You wager: \$"+player.wager+".")
game.pot = player.wager
game.pov.money = game.pov.money - player.wager
}
else {
msg ("You must enter a number.  Please try again.")
}
``````

You can change `game.minbet` or `game.maxbet` whenever you want to change the stakes.

Also, how does player.cash work with the wallet (if the wallet is, in fact, an object)?

The script is working, thanks for your help K.V.
The wallet is an undroppable inventory item that is added to the inventory at the beginning of the game. When you look at it, you get the following message:

A fine, leather-bound wallet.
You currently have \${player.cash} in cash.

That's how I decided to set it up, because I found the new built in money feature they added too confusing.

the 'get input' Script/Function stores your input AS A STRING VALUE into the built-in 'result' Variable VARIABLE:

result = YOUR_INPUT_AS_A_STRING_VALUE

so, if you want to work with numbers/amounts, you got to convert the string value into an 'int' or 'double' value:

// you input: 7
// result = "7" // the '7' is a 'string' Value, NOT an 'int' Value

input_as_integer_variable = ToInt (result)
// input_as_integer_variable = 7 // the '7' is an 'int' Value now

// or (working with doubles):

// you input: 7.4
// result = "7.4" // the '7.4' is a 'string' Value, NOT a 'double' Value

input_as_double_variable = ToDouble (result)
// input_as_double_variable = 7.4 // the '7.4' is a 'double' Value now

so to convert:

ToInt (xxx) // string to int
ToDouble (xxx) // string to double
ToString (xxx) // (int or double) to string

and, to check the value type first (before you then convert, if it's the right type):

IsNumeric (xxx) // is (int or double) ???
IsInt (xxx) // is int ???
IsDouble (xxx) // is double ???

here's an example:

``````<game name="example_game">
<attr name="start" type="script">
do (age_object, "age_script_attribute")
</attr>
</game>

<object name"room">
<inherit name="editor_room" />
</object>

<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="parent" type="object">room</attr>
<attr name="age_integer_attribute" type="int">0</attr>
</object>

<object name="age_object">
<inherit name="editor_object" />
<attr name="minimum_human_age_range_integer_attribute" type="int">17</attr>
<attr name="maximum_human_age_in_year_2017_integer_attribute" type="int">120</attr>
<attr name="age_script_attribute" type="script">
<![CDATA[
msg ("Age?")
get input {
if (IsInt (result)) {
input_integer_variable = ToInt (result)
if (input_integer_variable > minimum_human_age_range_integer_attribute and input_integer_variable < maximum_human_age_in_year_2017_integer_attribute) {
player.age_integer_attribute = input_integer_variable
msg ("Player Age: " + player.age_integer_attribute)
} else {
msg ("Wrong input, try again. Please type in an integer (non-decimal number) value between 18 and 120")
do (age_object, "age_script_attribute")
}
} else {
msg ("Wrong input, try again. Please type in an integer (non-decimal number) value")
do (age_object, "age_script_attribute")
}
}
]]>
</attr>
</object>
``````

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

Quest
Squiffy
ActiveLit

Documentation
Blog
GitHub

Forums