^comment when the program starts for the next time, it will start from here.
^comment This is the start of the program. if it is not the first run, skip to start.
BNZ $currentTime :Update
^comment If this is the first time running, set some default variables.
FUN @currentTime get_Creation_Timestamp
SET @ticketPrice #0000050000000000
SET @minNumPlayers #000000000000000f
SET @winnerPercent #0000000000000050
FUN @previousBalance get_Current_Balance
^comment by default, the creator wins.
FUN @currentWinner get_B1
^comment Normal AT runs here
FUN @currentTime get_Block_Timestamp
^comment if Lottery is over, just give me the BURST.
BNZ $deadAT :ErrorHandle
^comment check how much the PlayerPaid and convert to tickets
FUN @currentBalance get_Current_Balance
SET @newTicks $currentBalance
SUB @newTicks $previousBalance
DIV @newTicks $ticketPrice
^comment run internal lottery based on past tickets
SET @totalTicks $currentTickets
ADD @totalTicks $newTicks
^comment Random Number Generator
SET @myRandomSeed #000000000c5d6215
ADD @myRandomSeed $currentTime
FUN set_B1 $myRandomSeed
FUN get_A1 $myRandomNumber
^comment based on random number, figure out who won.
MOD @myRandomNumber $totalTicks
SET @currentTickets $totalTicks
BGT $myRandomNumber $currentTickets :ChangeWinner
^comment if the end time is set, jump to update2
BZR $endTime :Update2
^comment if time is up, end the lottery
BGT $currentTime $endTime :CloseAuction
^comment if there are enough players, set the end time.
BGE $currentNumPlayers $minNumPlayers :SetEndTime
^comment finish this run.
FUN @currentWinner get_Ticket_Id_for_Tx_in_A
^comment do not set endtime again if it has been set
BNZ $endTime :Update3
^comment set the end time to current time + 3 days.
SET @buffer1 #00000000000010e0
FUN @endTime add_Minutes_to_Timestamp $currentTime $buffer1
^comment we select a winner here and kill the AT
FUN set_B1 $currentWinner
^comment calculate payout
SET @buffer1 #000000000000000a
DIV @currentBalance $buffer1
MUL @currentBalance $winnerPercent
FUN send_to_Address_in_B $currentBalance
^comment die and give me money.
^comment reset the AT so that it give me all the money that people test with.
Should work as a lottery.. Now i just need to find out how to test my code.