I need some help thinking of a calculation for food supplies. Basically, the amount of time food supplies will last depends on the number of people in your army, which I count with “total_troops”.
Example: Say if I have 1000 units of food and an army of 100, it should last me 10 days. If in the next scene my army grows to 200, that food calculation should now update to say I have 5 days.
Can anyone good with math help me think of a way to calculate army-size vs food vs how long it will last?
I was thinking that 1 unit of food will correspond to enough food for 1 people for 1 day? Or something? idk
Calm down my friend! The CoG community is here to help. Seems that all you need is master the misteries of a *gosub command.
Lets work first on the variables:
The first one will be “time”.
A war demand time. in turns it could be days, weeks months… it dont matter. Is a number so lets convert it into a variable!
Is more or less like this:
*create time 0
*comment In Status page you cold set it: "Campaign length: ${time} fortnights"
you can also create variables for the army and food units. then you must create a *label to calculate accordly with the function our friend FairyGodfeather give to you. Then every time you use a turn, the time ad +1 and the subroutine actualizes the food surplus based on your variables.
Guess in the end is something like that.
*create temp 0
*create food x
*create troops y
*comment everytime you use one turn:
*set temp +1
*gosub food_consum
*label food_consum
*set food (food - troops)
*temp total_time (food / troops)
*If (food > troops)
You still got ${total_time} days worth of food for your troops!
*page_break
*return
*else
Warring! There is no food my liege!!!
*page_break
*return
Will me telling you the answer help you get better at coding?
I suck at coding too. The most important skills you can have though are a willingness to learn, and also the ability to teach yourself and find your own answers.
I did the math for you.
So consider this a puzzle and try and find the answer. Guess. Even if you guess wrong.
Subroutines are blocks hidden in a code or organizational structure that realizes repeatedly determined operation. Is a great tool to coders, administrators and Choicewriters.
I strongly suggest that you try to learn from the wiki and from the Choice of games help pages how to tame them. It will be of great help at you code!
If you’re going to make a game with more complex code, like you’re planning, I’d suggest trying to figure out how to do things first. I remember the first time I tried to wrestle with multiple if statements, they gave me such a headache. But when I finally figured it out, it was great. There’s still bits I find tricky, but you’ll learn more trying to do it yourself first.