How do I set a variable to be zero?
Jamie Furlong
07 Oct 2016, 10:29My player has money (player.money) but when he takes a bus journey he gets his wallet stolen. How do I set the amount to zero, bearing in mind the amount he loses varies depending upon what he bought previously (i.e. he could lose $20 or $25)?
Pertex
07 Oct 2016, 12:41Use an additional variable player.moneystolen and set it to the amount he loses. THen you can set player.money to zero
player.moneystolen=25
player.money=0
Pykrete
07 Oct 2016, 19:01Unless I'm misreading, you may be overthinking it.
You don't have to have a calculation; unless you need to track how much money he lost, you can just set money to 0. If you need him to go 'oh crap, I lost {x} dollars!' then Pertex's extra step works just dandy for that.
Personally, if it's only called on once, I have temp stats that I overwrite one they're done with. So if he never mentions the amount again, just do;
player.temp = player.money
player.money = 0
"Oh crap, I lost {player.temp} dollars!"
The Pixie
07 Oct 2016, 19:53Or do it the other way round.
"Oh crap, I lost {player.money} dollars!"
player.money = 0
hegemonkhan
07 Oct 2016, 21:34here's a guide I did on Attributes and the 'if' Script, though it's a bit code-heavy / technical / hard-to-understand-follow, but you can take a look at it, and hopefully you do understand/follow some of it, and if not, let me know and I can help further:
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
again, I'll be happy to help with anything, or to explain anything that isn't clear or making sense.
Jamie Furlong
08 Oct 2016, 10:48Thanks for the replies.
In Pertex's example you are assuming he has $25 on him. What I'm saying is that he may have $20 or he may have $25 depending up on what he bought before this time. I think Pixie's solution is the easiest.
BTW - when in Text+Script, how do you run scripts after the main text, or do you just have to rely on the 'print message' option to wrap it all in the correct order? It's a bit cumbersome when I want to print five paragraphs after running a script.
The Pixie
08 Oct 2016, 12:45BTW - when in Text+Script, how do you run scripts after the main text, or do you just have to rely on the 'print message' option to wrap it all in the correct order? It's a bit cumbersome when I want to print five paragraphs after running a script.
It is either text OR script, so yes, you have to put your print messages in the right order.