Revisting the budget screen prototype

Hey, I mentioned a while ago (#63 (closed)) that I had added some tracking to vanilla before that came to a close. It's going to take a bit of work to bring that back, and I want to make sure it is designed well, particularly so that it works well with JS. I'm still learning a lot here though, so I could use some guidance if anyone could do me a favor. I think I need to learn to use functions in the project since we're beyond widgets, but correct me if I am wrong.

In the end, the project allowed me to generate a finance sheet as well as detailed per slave records of weekly and lifetime profit.

Goal: write a function that replaces direct updates to $cash so it can track them. I'd like it to take four arguments:

  1. Money.
  2. Action. (whoring, etc)
  3. Location. (could merge with action, but not all whores are in the brothel, and it was useful to track what was made where.)
  4. Slave (who earned the money, who was it spent on.)

Then change $cash based on what happened. This also allows us to set up a sanity check for NaN on cash, and I can hopefully make a similar system for reputation eventually. 'Action' could be repurposed for capex and such.

I'd like to make something like cashTransaction(-1000, whoring, $brothel, $slave[$i]). Or cashTransaction(_seed, whoring, 0, $activeSlave)

The old prototype did this in two steps, something like this:

<<slavePaid $Attendant _seed>>
<<set $lastWeeksFinances.incomeSpa = _seed>>

slavePaid was a widget that would add the amount to a lifetime income tracker, and a weekly income tracker that was unique for each slave. It also "billed" the $cash variable:

<<widget "slavePaid">>

<<set $cash += $args[1]>>
<<if $args[1] > 0>>
	<<set $args[0].grossCashLastWeek += $args[1]>>
	<<set $args[0].lifetimeIncome += $args[1]>>
<<elseif $args[1] < 0>>
	/* No weekly cost record yet */
	<<set $args[0].lifetimeCost -= $args[1]>>
<</if>>

<</widget>>

Then I would write to the $lastWeeksFinances array to record what happened.

This was a bit of a mess, and I'd really like to have it all happen in one function.

In particular, I don't know how to call or update twine strings with a JS function, if I should indeed use functions instead of widgets.

Edited by lowercasedonkey