Interesting. I like the randomness.
I'll detail how you might go about maturing an investment:
Most simply: Funds mature by a constant value
1) Create an investment variable with a value of 0. This is how much money is currently in the investment.
2) If there is any money in the investment (investment > 0), add something like a dollar every frame (~$30 per second)
3) When the player buys stock, take some amount from their money to add to the investment
4) When the player sells stock, add the investment variable to the players money and set the investment var back to 0.
var investment = 0 // The current value of your investment var increase_rate = 1 // How much to increase the investment every frame var player_money = 10000 // How much money the player has var buy_price = 1000 // How much each stock costs forever: if (investment > 0): investment += increase_rate on_event sell_stock: player_money += investment investment = 0 on_event buy_stock: player_money -= buy_price investment += buy_price
Simple: Increase by a constant rate
The only difference between the last method is that we change how much to increase the investment by to be a rate, so that you get exponentially more money the longer funds are in:
var increase_rate = 1 // How much to increase the investment every frame forever: if (investment > 0): investment += increase_rate
var increase_rate = 0.01 // How much of the current investment we gain every frame forever: // 100 * 0.1 (10% of 100) is 10; add 10 to 100 investment += investment * increase_rate
Complex: variable rate + declines
Every frame, you could change the rate at which the investment changes. You could decrease it, make it negative, increase it, or make it positive:
var increase_rate = 0.01 // How much of the current investment we gain every frame forever: // 100 * 0.1 (10% of 100) is 10; add 10 to 100 increase_rate += get a random number between -0.1 and 0.1 investment += investment * increase_rate
Let me know if you have any questions!