# Input number and temp variable

Hi,
I am trying to write a routine where coins can be won and added to the total
I have set gold as a variable in startup and have begun writing the gosub
This is as far as I have got :

``````Test of gambling
*temp goldwin
*input_number gold 1 5

----

``````

As this is the winning option I want to double the number of coins bet but I can’t work out how to do this? How do I refer to the inputted number between 1 and 5 in the code? please

You need to *temp variables that you intend to use as number in a particular way – you have to tell choicescript that “goldwin” is a numerical variable. (like *temp goldwin 0)

*temp gold 0
*temp bet 0

*input_number bet 1 5

Stuff that determines if you win or lose

``````*if win
*set bet (bet * 2)
*set gold (gold + bet)
"You bet \${bet} and you now have \${gold} gold!
``````
1 Like

My example scenario will simply use a coinflip for clarity. If you want some kind of sophisticated gambling system, that should come out later.

This is my complete snippet.

``````*create gold 0
-------------
*temp goldbet 0
*temp coinflip 0
*temp coinwin 0
*temp coinpick 0
-------------
*label bet
*input_number goldbet 1 5
*if gold < goldbet
You don't have that much money. Pick again.
*goto bet
*else
*set gold - goldbet
Alright, you bet for \${goldbet} gold.

Now, what are you betting for?
*choice
*set coinpick 1
#Tail
*set coinpick 2
You've chosen tail.

Well, let's begin flipping!

*rand coinflip 1 2
*if coinflip = 1
*else
*set coinresult "tail"

The coin is flipped. It goes \${coinresult}.
*if coinpick = coinflip
*set gold + (2*goldbet)
You win!
*else