Calculation Help


Hello everyone.

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 :slight_smile: 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

Thanks in advance


Using 1 unit of food lasts 1 person for 1 day is a really good idea.

You want to have days = food / army size.

Using the above information can you work out how to code this yourself?


I’ll try…but I suck at coding XD


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!
  Warring! There is no food my liege!!!



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.

Use the ide. [Tool] ChoiceScript Development Environment
Use the wiki

When I’m trying to learn I will try command after command in the IDE over and over again tweaking things until I get the syntax right and it works.


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! :smiley:

The choicescript IDE is also great! i always use!


Thanks guys, it was super easy once I just put my mind to it. For some reason I was imagining something super complex


Choicescript is really easy.

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.