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 
Place your bet
*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

Place your bet
*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
Place your 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
   #Head
      *set coinpick 1
      You've chosen head.
   #Tail 
      *set coinpick 2
      You've chosen tail.

Well, let's begin flipping!

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

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

Thank you So much both
It took me 2 hrs this morning to get as far as I did, your example and how quickly you posted it is rather humbling! :smiley:

1 Like

I’m not sure whether my snippet is bug-free, as it’s simply something that pops out of mind. So, do keep in mind about that. However, it should cover most of the basics to make a functional betting system.

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the @moderators.