Please add Modulo to S&S Editor Logic Syntax (Full Version)

All Forums >> [New Releases from Matrix Games] >> Shadow Empire >> Suggestions and Feedback



Message


zgrssd -> Please add Modulo to S&S Editor Logic Syntax (5/11/2021 12:51:26 PM)

The Modulo Operator (% in C#) is one of those Operations where at first you have no idea "what is it even good for?"
And once you realize, you can not live without it.

Y % X == 0
checks if Y can be divided by X without rest.

The most common example would be to check if a number is even:
Y % 2 == 0


But you can also do some other usefull stuff like "every 20th Turn":
ROUND % 20 == 0


I tried to approxmiate it with simple division, but
3 / 2 == 1
is true. As naturally with Integers, 3/2 rounds down to 1. And 1 == 1
I will have to use a large list of or checks like:
ROUND == 20 | ROUND == 40 | etc.




DeltaV112 -> RE: Please add Modulo to S&S Editor Logic Syntax (5/11/2021 2:46:30 PM)

Presuming we're using integer division.
X % Y == X - (X / Y * Y)




zgrssd -> RE: Please add Modulo to S&S Editor Logic Syntax (5/11/2021 4:48:14 PM)


quote:

ORIGINAL: DeltaV112

Presuming we're using integer division.
X % Y == X - (X / Y * Y)

If the game does any variable pruning, it might just be executed as "X % Y == X - X" Or X % Y == 0.
And I would need to check if it even covers all cases properly mathematically.

Plus either way, it is a pretty huge waste of calculation and excessively verbose code - for something that CPU's have hardware level support for [;)]




zgrssd -> RE: Please add Modulo to S&S Editor Logic Syntax (5/12/2021 10:19:58 AM)

I think I can use story+decision logic for something here, that would also allow catching up with any missed events:
$dueInstances$
$triggeredInstances$

# Executed each turn
if($dueInstances$+1 * 20 >= ROUND)
  $dueInstances$ = $dueInstances$+1

# Then in the actuall event:
if($dueInstances$ > $triggeredInstances$)
  # Do the event
  $triggeredInstances$ = $triggeredInstances$ +1

Still I would prefer being able to just use "ROUND % 20 == 0".




DeltaV112 -> RE: Please add Modulo to S&S Editor Logic Syntax (5/14/2021 8:28:21 PM)

quote:

ORIGINAL: zgrssd
If the game does any variable pruning, it might just be executed as "X % Y == X - X" Or X % Y == 0.
And I would need to check if it even covers all cases properly mathematically.

Plus either way, it is a pretty huge waste of calculation and excessively verbose code - for something that CPU's have hardware level support for [;)]

If the game is doing pruning in this case it's a bug, no matter how you slice it divide then multiply by same value is not equivalent to doing nothing. And in performance terms it's irrelevant- your CPU can demolish math like this, and if this somehow does become a performance bottleneck modern CPU's can recognize idioms like this and change the instruction flow(if this were using a non-custom language the compiler would certainly recognize it).




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.6875