A little mathematics/logic problem - help pls?


I’m kinda’ embarrassed to ask something like this but I need a solution for a (probably very simple) math/logic problem:

MyActor1 requests 100 Units from Actor2 who only has 50.
How do I make sure that MyActor1 only gets 50 which are actually “taken” off actor 2 and setboth variables accordingly (A1’s to 50 and A2’s to 0 respectively).
So far, I’ve only been able to make A2 go into -50 to satisfy the request - I’m stuck.

As I said, It’s embarrassing, but apparently after 12 years of intensive mathematics I’m unable to use ANY of it in real-life/logic situations…Give me “typical” calculus problems and I can solve them, without really understanding anything.

Hope someone will actually waste their time answering something like this :stuck_out_tongue:

Thanks! :slight_smile:

  1. Actor1 requests 100 units from Actor2
  2. Branch node…(Requested Units - Available Units >= 0?)
  3. If “yes” set Actor1 units to “requested” value, set Actor2 units to “Avaliable - Requested”
  4. If “no” but Actor1 will receive ALL of Actor2’s units then Set Actor1 units to “Actor1 Units + Actor2 Units”. Then Set Actor2 Units to 0.

Sometimes using a mix of ‘Max’ & ‘Min’ or other simple logic functions can help:

Actor2 = Max(Actor2 - MyActor1,0)
MyActor1 = Min(MyActor1, Actor2)

If Actor2 = 50, MyActor1 = 100 → Actor2 = 0, MyActor1 = 50
If Actor2 = 100, MyActor1 = 50, Actor2 = 50, MyActor1 = 50
If Actor2 = 100, MyActor1 = 100, Actor2 = 0, MyActor1 = 100
If Actor2 = 250, MyActor1 = 100, Actor2 = 150, MyActor1 = 100

When you’re stumped using a spreadsheet like LibreOffice / MS Office etc can help (similar to working out logic-state-tables in your game). Write out some sample values (inputs), then next to that in a table, write out resulting values (outputs) you need to obtain (and know to be correct). Then just try some simple math to see if you can get there (or find a simple formula to get the desired numbers / state values). It won’t always work, but it may help you to see the bigger picture, and at least understand the problem better. Whereas deep in code sometimes its harder to get there (see simple truths etc)… :stuck_out_tongue:

Hello Florian, from the amount requested and the amount owned you have to take the minimum of both, and for that you have a specific operator that will return you the minimum value.
I attached a pic, hope it helps :wink:

Yes! Thank you Ramon! Exactly what I was looking for!

Thank you all for your inputs. Maybe I didn’t explain the complexity of the problem, but that was just an example. I got various trade-relationships between my BPs and I was looking for a more abstract solution, something I can generalize regardless of actual values. I’ve tried using endless bools but the logic is flawed and breaks down in certain situations, for instance:
First call: A1 has 4 units, A2 requests 12 => A2 will get only 4, A1 will be left with 0 >>
Second call: A1 has 6 units, A2 requests only 8 [12-4], receives only 6 and A1 is left with 0 again…
…And so on.
It’s for a worker allocation pool where the manager BP holds/receives the workers and various other BPs calls a request for them…It’s dynamics based on other mechanics which means that values in the manager can change at any time, and requests keep calling until they get satisfied, after which they are handled.

Thank you all!